HowTo: Get the selected list index on Android Activity from context menu event
1 min read
1 min read
//the selected indexIt is as simple as that. If you registered a context menu on the list, then the situation changes slightly and the "getSelectedItemPosition()" will fail. Instead, you have to do something like this
int index = listView.getSelectedItemPosition();
//selected item
Object selObj = listView.getSelectedItem();
AdapterView.AdapterContextMenuInfo menuInfo;
menuInfo = (AdapterView.AdapterContextMenuInfo)item.getMenuInfo();
int index = menuInfo.position;