You need to call registerForContextMenu in the view.
EDITED to add a call to setLongClickable (false)
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { registerForContextMenu( view ); view.setLongClickable(false);
You will also need to actually add menu items, otherwise the menu will not be displayed. Setting the title is not enough.
NOTE. I have not fully traced this yet, but calling registerForContextMenu (view) sets a flag assuming that you want the context menu to last a long time. When this flag is set, the onTouch logic in AbsListView somehow no longer triggers onClick. I donβt have time to completely slip through. It seems that when using a simple adapter such as an ArrayAdapter and using ListActivity with a ListView by default, you will need to decide whether the context menu can appear on a short click or use longclick.
If you do not need long presses, you can configure the context menu for a short press by canceling the flag set in registerForContextMenu (view);
Perhaps someone has more information or more time to dig through the code.
slund
source share