I'm trying to create a context menu that changes the available options depending on which row was clicked.
But I can't figure out how to get the row position in the listview for row that was clicked, until after the menu is created.
I'm trying to create a context menu that changes the available options depending on which row was clicked.
But I can't figure out how to get the row position in the listview for row that was clicked, until after the menu is created.
It is not obvious at all, but here's the code:
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo)
{
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
int position = info.position;
The above solution did not work for me. Here is what I used:
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenu.ContextMenuInfo menuInfo) {
menu.add(0, v.getId(), 0, context.getString(R.string.tabTitleEnrolment));
menu.add(0, v.getId(), 0, context.getString(R.string.tabTitleAfterCare));
menu.add(0, v.getId(), 0, context.getString(R.string.contextMenuDelete));
pos = getPosition();
}