Android的OnKeyListener不注册输入键和搜索键。 [英] Android OnKeyListener not registering Enter and Search keys.
本文介绍了Android的OnKeyListener不注册输入键和搜索键。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用的是弹出窗口,在该窗口中我有一个搜索视图。当点击搜索视图中的软键盘来在屏幕上。所以我想,每当我preSS搜索按钮或从keybaord它将从搜索视图获取数据输入按钮,会显示相关信息。我使用的是 OnKeyListener
拿到钥匙,但它未在注册输入和搜索键presses。
我的code:
searchview.setOnKeyListener(新OnKeyListener(){
@覆盖
公共布尔安其(查看为arg0,ARG1 INT,KeyEvent的ARG2){ 如果(arg2.getKey code()== KeyEvent.KEY code_SEARCH || arg2.getKey code()== KeyEvent.KEY code_ENTER){
popupwindow.setFocusable(假);
的System.out.println(搜索pressed);
Toast.makeText(getApplicationContext(),搜索pressed,0).show();
}
返回false;
}
});
解决方案
使用arg2.getAction()而不是getKey code(),它应该工作。
I am using a Popup window and within that window I have a search view. Upon clicking the search view the soft keyboard comes on screen. So I want whenever I press the search button or enter button from keybaord it will get the data from the search view and will show the relevant information. I am using an OnKeyListener
to get the key but it is not registering the enter and search key presses.
My code:
searchview.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View arg0, int arg1, KeyEvent arg2) {
if(arg2.getKeyCode() == KeyEvent.KEYCODE_SEARCH || arg2.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
popupwindow.setFocusable(false);
System.out.println("search pressed");
Toast.makeText(getApplicationContext(), "Search Pressed", 0).show();
}
return false;
}
});
解决方案
Use arg2.getAction() instead of getKeyCode() and it should work.
这篇关于Android的OnKeyListener不注册输入键和搜索键。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文