我对TextWatcher有一个恼人的问题 . 我一直在网上搜索,但找不到任何东西 . 感谢有人能帮助我 .
For some reason the calls to the TextWatcher events upon one text change are erratic. sometimes they are being triggered once (like they should be), sometimes twice, and sometimes 3 times. have no idea why, the whole thing is very straight forward. also sometimes the Editable parameter on afterTextChanged() returns empty values in toString() and length().
代码如下:
private TextWatcher mSearchAddressTextChangeListener = new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) { }
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) { }
@Override
public void afterTextChanged(Editable searchedAddress) {
System.out.println("called multiple times.");
}
};
在 afterTextChanged() (和 AsyncTask )里面我没有对文本或 EditText 视图进行任何更改 .
无论如何,感谢任何帮助 .
EDIT: 我删除了afterTextChanged()的内容,导致即使没有我的代码也会发生此问题 . 是什么让我相信这是一个错误 . 在常规字符(事件处理程序被触发两次)之后立即输入'space' char或在删除常规字符之后输入'space'字符(退格 . 事件处理程序被触发3次)时,会发生错误 . 帮助仍将受到赞赏 .