If there is a long tap on the text field, a pop-up appears with a list of possible actions (select a word, etc.). How to hide / show it programmatically?

PS: Instead of this menu, I need a long tap, to start my processing. At the moment it starts, but this popup still appears.

  • and if i need my longtap handling? - st_er
  • 3
    then you make your handler, OnLongClickListener, if memory serves - Sevak Avetisyan
  • one
    You must tell the system that the event has been processed: public boolean onLongClick (View v) {// Your code return true; } then the context menu will not be called - woesss

1 answer 1

Oops, but the answers of colleagues above in kamentah - alas, are incorrect.

In Android, with a long tap, 2 independent actions are performed:

  1. OnCreateContextMenu() - called before creating the context menu
  2. OnLongClickListener()

The menu that appears is the context menu and it is processed by calling super.OnCreateContextMenu() - if you do not call it, the system menu will not appear.

  • one
    Regarding independence, I do not agree onCreateContextMenu () - will be called by the system only if View is long-clickable and the OnLongClickListener handler is not defined or returns false. Which of these conditions to "break" depends on the desired result - woesss
  • Sure? Even if editText.setLongClickable(false); context menu will be called :) - Barmaley
  • one
    @Barmaley ♦ you are right, long-clickable does not matter here. That at me the device has priglyuchil - on emuls the menu is really caused - woesss
  • @woesss nothing bad happens. I plowed this feature with my own face a couple of years ago in all guises :) - Barmaley