Domanda

In Android is it possible to register a View for context menu, so that the menu will show up when it is double tapped instead of when a long press action has been registered? I have a view with a scroll functionality. This view is also registered for a context menu. Whenever a scroll is performed on this view and the scroll action takes a certain amount of time the long press action is triggered and the context menu pops up. In order to avoid this situation I would like to make the context menu appear when the view is double tapped rather than when it is pressed long.

È stato utile?

Soluzione

For anyone who has run into this problem. What I ended up doing was to listen for the long press with the GestureListener. Once the long press event is triggered, I register the view for a context menu with registerForContextMenu(View v), then call openContextMenu(View v).

And in order to not have the context menu pop up and interfere with the long press event, I overrode the onContextMenuClosed(Menu menu) method, in which I call unregisterForContextMenu(View v) passing the view that I earlier registered.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top