Skip to content Skip to sidebar Skip to footer

Can You Intercept The Long Press On Menu?

I'm using what should be pretty simple code, but it just doesn't want to work. Does the OS block intercepting this? @Override public boolean onKeyLongPress(int keyCode, KeyEvent ev

Solution 1:

You must call startTracking() on the event from the normal onKeyPress() method:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_MENU) {
        event.startTracking();
        returntrue;
    }
    return super.onKeyDown(keyCode, event);
}

See also a question I asked and answered some time ago.

Solution 2:

If it is ListView, You need to use onCreateContextMenu.

publicvoidonCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo)

Post a Comment for "Can You Intercept The Long Press On Menu?"