I have a ListView
filled with a CustomAdapter
that should display a ContextMenu
after a long click.
I try to do it like such:
// in OnCreateView
ListView list = (ListView) view.findViewById(R.id.list);
registerForContextMenu(list);
and
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater inflater = getActivity().getMenuInflater();
inflater.inflate(R.menu.todo_context_menu, menu);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.edit:
// Do something
return true;
case R.id.delete:
// Do something
return true;
default:
return super.onContextItemSelected(item);
}
}
And my todo_context_layout.xml
being:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/edit" android:title="Edit"/>
<item android:id="@+id/delete" android:title="Delete"/>
</menu>
A long click does trigger the OnItemLongClickListener
but does not display a context menu. What am I doing wrong?
After reading the following thread, I could not find the answer to my question.