Skip to content Skip to sidebar Skip to footer

Keyevent Handling In Android?

I want to programattically handle the ENTER key in android. Is there any way to achieve this? Please Help!! Thanks in advance

Solution 1:

You need to carefully override the following function:

@OverridepublicbooleanonKeyDown(int keyCode, KeyEvent event) {

    switch (keyCode) {
        case KeyEvent.KEYCODE_ENTER:
        {
            //your Action codereturntrue;
        }
    }
    returnsuper.onKeyDown(keyCode, event);
}

Solution 2:

Use onKey() to capture the key. KEYCODE_NUMPAD_ENTER is used for the numeric ENTER key, and KEYCODE_DPAD_CENTER is the Directional Pad Center key.

Post a Comment for "Keyevent Handling In Android?"