我想在选择上下文菜单项时打开 aboutActivity,但是当我从上下文菜单中选择任何项目时没有任何反应。
这是代码:
public boolean onContextItemSelected(MenuItem menu){
// get menu id
int menuid = menu.getItemId();
switch (menuid){
case 0:
Intent intnt2 = new Intent(ListActivity.this,aboutActivity.class);
startActivity(intnt2);
break;
case 1:
Intent intnt3 = new Intent(ListActivity.this,aboutActivity.class);
startActivity(intnt3);
break;
}
return super.onContextItemSelected(menu);
}
我已经在清单文件中声明了 aboutActivity,并且我有另一个菜单项(名为“About”)启动 aboutActivity.Any 帮助?
[编辑] 这是 onCreateContextMenu 函数:
public void onCreateContextMenu(ContextMenu menu,View view,ContextMenuInfo menuInfo){
//checking if the long press is coming from ListView or not
if(view.getId()==R.id.mainlist){
//AdapterView.AdapterContextMenuInfo ainfo= (AdapterContextMenuInfo) menuInfo;
menu.setHeaderTitle("Item menu");
menu.add(Menu.NONE,0,0,"Edit");
menu.add(Menu.NONE,1,0,"Delete");
}
}
正如 raghunandan 建议的那样,如何在这里使用 R.id?