当我点击列表项时,它不会启动新活动。是什么原因?其他人已经实现了相同的代码,并且程序正在运行。我该怎么办这个问题? 这是代码:
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();
}
}
}
请帮忙。
答案 0 :(得分:1)
您需要在onCreate()中设置点击的监听器
@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));
ListView lv = getListView();
lv.setOnItemClickListener(this);
}