我有兩個按鈕,每個都有一個上下文菜單,但我不確定如何更改第二個菜單中的菜單項。我的代碼只顯示我的第一個按鈕的項目。如何將不同的菜單項添加到多個上下文菜單?
Button Button1 = (Button) findViewById(R.id.Button1);
registerForContextMenu(Button1);
Button Button2 = (Button) findViewById(R.id.Button3);
registerForContextMenu(Button2);
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v,ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
menu.setHeaderTitle("Select Notification");
menu.add(0, v.getId(), 0, "Algebraic");
menu.add(0, v.getId(), 0, "Knuckle Train");
menu.add(0, v.getId(), 0, "In My Element ");
menu.add(0, v.getId(), 0, "Let's Get This Party");
menu.add(0, v.getId(), 0, "Shmowzow");
menu.add(0, v.getId(), 0, "What the Jug");
menu.add(0, v.getId(), 0, "Word to Your Mother");
}
@Override
public boolean onContextItemSelected(MenuItem item) {
if(item.getTitle()=="Algebraic"){function1(item.getItemId());}
else if(item.getTitle()=="Knuckle Train"){function2(item.getItemId());}
else if(item.getTitle()=="In My Element"){function3(item.getItemId());}
else if(item.getTitle()=="Let's Get This Party"){function4(item.getItemId());}
else if(item.getTitle()=="Shmowzow"){function5(item.getItemId());}
else if(item.getTitle()=="What the Jug"){function6(item.getItemId());}
else if(item.getTitle()=="Word to Your Mother"){function7(item.getItemId());}
else {return false;}
return true;
}
非常感謝,人來完成!這就是訣竅。 – adneal 2011-03-14 04:40:04