I have a View that extends Activity. A ListView will display a number of listitems. When the user long clicks I would like to present them with a contextmenu allowing them to select edit, delete etc... and then identify the listitem that was selected as the item to perform the action on.
In onCreate I have:
listView.setAdapter(adapter);
listView.setOnItemClickListener(onListClick);
listView.setOnItemLongClickListener(onListLongClick);
registerForContextMenu(listView);
I have a method onCreateContextMenu
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
menu.setHeaderTitle("Context Menu");
menu.add(0, v.getId(), 0, "Edit");
menu.add(0, v.getId(), 0, "Delete");
}
and also onContextItemSelected
@Override
public boolean onContextItemSelected(MenuItem item) {
if (item.getTitle() == "Edit") {
// edit action
} else if (item.getTitle() == "Delete") {
// delete action
} else {
return false;
}
return true;
}
I am not sure where to go from here to get the correct row/listitem.