TextEdit值改变时如何触发?
我尝试了这个:
houseField.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
// 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 onTextChanged(CharSequence s, int start, int before,
int count) {
// TODO Auto-generated method stub
Toast.makeText( getApplicationContext(), s, 15000).show();
}
});
但是插入每个符号后都会触发事件,但我不希望这样。
当用户离开文本编辑并且文本发生更改时,我需要触发事件,因为我将对谷歌地图API进行查询。输入每个字符后我无法进行查询。
I tried this:
houseField.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
// 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 onTextChanged(CharSequence s, int start, int before,
int count) {
// TODO Auto-generated method stub
Toast.makeText( getApplicationContext(), s, 15000).show();
}
});
But event triggered after each symbol inserted but I dont want that..
I need to trigger event when user leaves textedit and text is changed, becouse i will do query to google maps api. I can't do query after each character entered.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否尝试过 onFocusChanged()
另一种选择是使用 onTextChanged 启动计时器,该计时器会检查延迟过程并在发生另一次击键时重置。这种方法可能更适合您的应用程序,但实现起来比较困难
EDIT
或者,您可以覆盖
boolean View.onKeyPreIme(int keyCode, KeyEvent event)
并捕获 Enter 键(但您还需要考虑用户点击后退键来关闭键盘)。Have you tried onFocusChanged()
The other option is to use onTextChanged to start a timer which checks to delay the process and reset if another key stroke happens. This approach may be more suitable to your application but is trickier to implement
EDIT
Alternatively you can override
boolean View.onKeyPreIme(int keyCode, KeyEvent event)
and capture the enter key ( but you will also need to think about the user tapping the back key to dismiss keyboard).}
}