multiple lists with different contextMenus
I have a viewFlipper with different ListViews in each "flip". I have made all the lists registerForContextMenu(chosenList);
and the longPress menu appears in each of the lists as I want.
Now I want to have DIFFERENT contextMenues in the different list views. eg. one list with network info will have network related choices in the contextMenu and the list with friend开发者_开发知识库s will have another set of choices in it's contextMenu.
How do I do this efficiently? is this even possible?
public void onCreateContextMenu(ContextMenu menu2, menu3, menu4, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu2, menu3, menu4, v, menuInfo);
menu2.setHeaderTitle("Quick Menu");
menu3.setHeaderTitle("Menu3");
menu4.setHeaderTitle("Menu4");
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.context_menu, menu2);
inflater.inflate(R.menu.context_menu3, menu3);
inflater.inflate(R.menu.context_menu4, menu4);
}
...or ...? how else? this is starting to drive me insane in the midbrain... :D
Inside your onCreateContextMenu(), do something like:
switch(v.getId())
{
case R.id.list1:
{
inflater.inflate(R.menu.context_menu1, menu)
break;
}
case R.id.list2:
{
inflater.inflate(R.menu.context_menu2, menu)
break;
}
}
精彩评论