EditText 需要单击两次才能打开搜索对话框
我的应用程序有两个 EditText 元素。两者都实现了如下所示的 OnClickListener:
editText1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Open search dialog
doSomeStuff();
}
});
doSomeStuff()
意思是:单击文本字段通过 onSearchRequested()
打开一个搜索对话框。搜索结果被写回文本字段。
这工作正常,但如果我单击其他文本字段,我总是必须在搜索对话框出现之前单击两次。它从哪里来?如何更改它,以便仅单击一次时就会出现搜索对话框?
My application has two EditText elements. Both implement the OnClickListener like this:
editText1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Open search dialog
doSomeStuff();
}
});
doSomeStuff()
means: Clicking on the text field opens a search dialog via onSearchRequested()
. The search result is written back to the text field.
This works fine but if I click the other text field I always have to click twice before the search dialog comes up. Where does that come from and how can I change that so that the search dialog comes up when clicking only once?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于 EditText 字段,最好使用 OnKeyListener。通过传入的 KeyEvent,您可以根据 EditText 字段被单击/获得焦点的方式做出不同的反应。否则,您也可以尝试 OnFocusChangeListener 或者如果您想使用 TextWatcher 来查看添加的每个字符,您可以实现 TextWatcher 并使用 addTextChangedListener 。
For EditText fields it is better to use an OnKeyListener. With the passed in KeyEvent you can then react differently depending on how the EditText field got clicked/get focus. Otherwise you can also try a OnFocusChangeListener or if you want to use TextWatcher to see each character that is added you can implement a TextWatcher and use addTextChangedListener..