0
当我点击一个List Item时,它不会开始一个新的活动。是什么原因?其他人已经实现了相同的代码,并且程序正在工作。我该怎么处理这个问题? 这里是代码:Android ListItem不工作
public class Menu extends ListActivity {
String classes[]={"StartingPoint","Splash", "You", "Dumb"};
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, classes));
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
String cheese = classes[position];
try {
Class ourclass = Class.forName("com.umer.splashscreenwithsound." + cheese);
//Class ourclass = Class.forName("com.umer.splashscreenwithsound.StartingPoint");
Intent myintent = new Intent(Menu.this,ourclass);
startActivity(myintent);
} catch(ClassNotFoundException e) {
e.printStackTrace();
}
}
}
请帮忙。
您是否获得,同时单击某个项目的任何异常或没有动静的监听器设置? – Praveenkumar 2012-08-02 14:05:04
您是否为清单中的每个类创建了条目? – 2012-08-02 14:11:07
您的字符串数组中的项目是如此...琐碎....:D(抱歉,嘿嘿)。你是否在调试器中运行代码?如果您将断点放入它,它会进入onListItemClick方法吗?检查这篇文章http://www.vogella.com/articles/AndroidListView/article.html – 2012-08-02 14:19:28