1

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

Thanks in advance

info
  • 2,152
  • 5
  • 22
  • 38

2 Answers2

2

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);
}
Zelimir
  • 11,008
  • 6
  • 50
  • 45
1

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.

Rajath
  • 11,787
  • 7
  • 48
  • 62