EditText TextChangeListener问题
我有一个用于搜索目的的编辑文本。我已经添加了
searchET.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
//intent to another page where i show my search result
}
});
问题是: 当我给出例如“fort”的搜索字符串时,我会在下一页中得到所需的结果。但是,当我按后退按钮时,第一次单击时它不会移至上一页。我必须按后退按钮 4 次才能转到上一页。这是因为我的搜索字符串的长度为 4,每次在 edittext 中输入一个值时,都会调用 textchangelistener。我该如何解决这个问题?请回复。提前致谢。
I have an edit text meant for searching purpose. I have added
searchET.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
//intent to another page where i show my search result
}
});
The problem is:
When I give a search string for eg: "fort" i get the required result in the next page. But when I press the back button, it doesnt move to the previous page on its first click. I will have to press back button 4 times to goto the previous page. This is because my search string is of length 4 and each time a value is entered into the edittext, the textchangelistener is called. How can I solve this issue? Please reply. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据您的需要,您可以根据某些条件进入下一页。例如,启动一个计时器,如果在计时器到期之前调用了afterTextChanged,则重置计时器。或者,您可以使用“搜索”按钮,用户可以在其中明确指示他已完成输入该单词。
如果您可以分享所需的行为,则可以建议更好的替代方案。
Depending on what you need, you can go to the next page based on some condition. For example, start a timer, and if the
afterTextChanged
is called before the timer expires, reset the timer. Alternatively, you can have a button 'Search' where the user explicitly indicates that he's done typing the word.If you can share the required behaviour, better alternatives can be suggested.
实际上,当您想决定文本何时结束时,没有必要包含 addTextChangedListener。要改进 UI,您可以将此按钮添加到您的编辑文本中。请参阅:使用视图编辑文本
actually when you want to decide when the text ends there is no point of including an addTextChangedListener. To improve the UI you could add this button into ur edit text .refer this : edittext with view