I have a TabHost with 2 Fragments, both lists. The onCreateContextMenu works fine for both, but both onContextItemSelected are "pointing" to the first Fragment class. I'm using different names for the lists in the XML files, so the ID isn't the same.
Here is the code for both onCreateContextMenu
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
int itemID = info.position;
Map m = (HashMap) this.listView.getAdapter().getItem(itemID);
menu.setHeaderTitle(getString(R.string.options));
menu.add(0, v.getId(), 0, activity.getString(R.string.delete));
}
And here onContextItemSelected for the first Fragment, second one is pretty much the same code just changing var names. In fact this doesn't change anything to the question, since this method only runs on the first Fragment, even when I'm on the second list.
@Override
public boolean onContextItemSelected(MenuItem item) {
ContextMenuInfo menuInfo = (ContextMenuInfo) item.getMenuInfo();
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
int itemID = info.position;
Map m = (HashMap) this.listView.getAdapter().getItem(itemID);
processId = Integer.parseInt(m.get("processId").toString());
activity.setSupportProgressBarIndeterminateVisibility(true);
runBackground(activity.getString(R.string.accessingECM), false, false, ACTION_REMOVE);
return true;
}
This is how I register for context menu on the onActivityCreated method. Note that the onCreateContextMenu works for both Fragment.
listView = (ListView) this.view.findViewById(R.id.listProcess);
registerForContextMenu(listView);
I tried to change the menu.add() 1st and 3rd parameters to (1,1) and (1,2). Also tried both to be Menu.NONE. Still doesn't work.
Thanks