KeyEvent handling in android?

拈花ヽ惹草 提交于 2021-01-28 08:17:07

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!