I'm working with a custom ListView, which implements dragging elements to reorder them. The reordering is initiated by long click.
I'd also like to open the context menu for each element in the list by a single, short click, like this (code from the fragment containing the list view):
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
mainFragment.this.getActivity().openContextMenu(view);
}
});
The problem is, that internally Android apparently opens the context menu by calling the onItemLongClick
method of the view's OnItemLongClickHandler
(source), which obviously causes the dragging behaviour to initiate.
How could I circumvent this behaviour?
I figured it out. You can set a private boolean variable to true in onItemClick, and suppress all behaviour in onItemLongClick, if this boolean variable is true: