info
info

Reputation: 2182

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

Upvotes: 1

Views: 3043

Answers (2)

Zelimir
Zelimir

Reputation: 11038

You need to carefully override the following function:

@Override 
public boolean onKeyDown(int keyCode, KeyEvent event) {

    switch (keyCode) {
        case KeyEvent.KEYCODE_ENTER:
        {
            //your Action code
            return true;
        }
    }
    return super.onKeyDown(keyCode, event);
}

Upvotes: 2

Rajath
Rajath

Reputation: 11946

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.

Upvotes: 1

Related Questions