0
好的,所以我对Android比较陌生,而且在菜单项名称方面遇到了一些麻烦。我会尽我所能解释这一点。Android菜单项名称
public class Menu extends ListActivity{
//Should be named the same as the Class itself
String classes[] = { "example1", "example2", "example3", "example4", "example5"};
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(Menu.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
String classPosition = classes[position];
super.onListItemClick(l, v, position, id);
try{
Class testClass = Class.forName("com.Test." + classPosition);
Intent testIntent = new Intent(Menu.this, testClass);
startActivity(testIntent);
}catch(ClassNotFoundException e){
e.printStackTrace();
}
}
}
我目前使用这种方法,但我遇到的问题是,所显示的菜单上的名字必须是一样的类名称为它工作。如果我想调用名为“测试”的活动,则显示的名称必须是“测试”。如果我有更多时间,我相信我可以弄清楚这一点,但我不知道。任何帮助表示赞赏。谢谢。
我想试试。谢谢。 – killerunicorn7 2012-01-18 23:13:34