问题
I want to programattically handle the ENTER key in android. Is there any way to achieve this? Please Help!!
Thanks in advance
回答1:
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);
}
回答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.
来源:https://stackoverflow.com/questions/5631977/keyevent-handling-in-android