问题描述
我在我的活动中使用AutoCompleteTextView,我需要它的DropDownList才能显示所有的时间(它是唯一的窗口中的View),即使在Back按键之后。我需要关闭软键盘。我试图覆盖Activity的onBackPressed方法,但是根本没有使用,所以BackPressed事件正在处理更高的地方。所以我试图找出哪里,但AutoCompleteTextView没有定义的onBackPressed方法。
任何建议?
您可以创建自定义AutoCompleteTextView并覆盖方法onKeyPreIme(int keyCode,KeyEvent事件)
我也意识到这种方法被称为2次,我只在第二次运行我的代码。这是一个例子:
@Override
public boolean onKeyPreIme(int keyCode,KeyEvent event){
if(keyCode == KeyEvent.KEYCODE_BACK&& event.getAction()== 1){
//在这里添加你的代码
return true;
}
return super.onKeyPreIme(keyCode,event);
}
i am using AutoCompleteTextView in my Activity and i need it's DropDownList to be shown all the time (it's the only View in Window), even after Back key press. I need to dismiss soft keyboard instead.
I tried to override Activity's onBackPressed method, but it's not used at all, so BackPressed event is being handled somewhere "higher". So i tried to find out where, but AutoCompleteTextView has no onBackPressed method defined.
Any advices?
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);
}
这篇关于按下Back键后如何保持AutoCompleteTextView的DropDownList打开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!