I use this code to get the Clicked Item position in the context menu:
public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); int index = info.position; }
as suggested here:
Android: how to find the position pressed from the context menu
But I get a NullPointerException in the line:
int index = info.position;
why is that so?
EDIT
I have 2 registered views for the Menu context like this:
button1.onClick(view v){ registerForContextMenu(v); openContextMenu(v); } button2.onClick(view v){ registerForContextMenu(v); openContextMenu(v); }
then depending on v.getId () I started the menu.
source share