上的EditText打onKey两次回车键 [英] Enter key on EditText hitting onKey twice
问题描述
我已经连接了OnKeyListener到一个EditText。我已经覆盖了onKey处理程序捕获的KeyEvent。
当用户点击回车键(无论是自己的电脑输入键同时使用模拟器或硬件上输入自己的手机按键与硬件键盘),该onKey处理程序被执行两次。这两个执行有钥匙code 66。
这是怎么回事?
我希望我的屏幕,这样当用户点击回车键,执行搜索。因为所发生的事情的,搜索不必要发生两次。
我的方法是这样的:
mFilter.setOnKeyListener(新View.OnKeyListener(){
公共布尔onKey(视图V,INT关键code,KeyEvent的事件){
如果(键code == KeyEvent.KEY code_ENTER){
//执行搜索
返回true;
}
返回false;
}
});
AHHHH
我认为这正在发生的关键和重点下来了吗?
I've attached an OnKeyListener to an EditText. I've overrode the onKey handler to capture a KeyEvent.
When a user hits the enter key (either their computer enter key while using the emulator, or the hardware enter key on their phone with a hardware keyboard), the onKey handler gets executed twice. Both executions have the keyCode 66.
Why is this happening?
I want my screen so when the user hits the enter key, a search is performed. Because of what is happening, the search is needlessly happening twice.
My method looks like this:
mFilter.setOnKeyListener(new View.OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_ENTER) {
// perform search
return true;
}
return false;
}
});
Ahhhh
I think this is happening for key up and key down?
这篇关于上的EditText打onKey两次回车键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!