I am using this code to get the Clicked Item position on 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 clicked from the context menu
But i get NullPointerException at line:
int index = info.position;
why is it so?
EDIT
I have 2 registered Views for the contextMenu like this:
button1.onClick(view v){
registerForContextMenu(v);
openContextMenu(v);
}
button2.onClick(view v){
registerForContextMenu(v);
openContextMenu(v);
}
then depending on v.getId() i populate the menu.