How to keep DropDownList of AutoCompleteTextView opened after pressing the Back key?

ε祈祈猫儿з 提交于 2019-12-05 15:13:58

You can create your custom AutoCompleteTextView and Override the method onKeyPreIme(int keyCode, KeyEvent event)

I also realized that this method is called 2 times, I'm running my code only in the second time. Here is the example:

@Override
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == 1) {
        //add your code here
        return true;
    }
    return super.onKeyPreIme(keyCode, event);
}

You may try this

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
            //Your back key press logic
    }
    return true;
}

Remember to return true to prevent this event from being propagated further, or false to indicate that you have not handled this event and it should continue to be propagated.

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