java 事件重复执行_TextWatcher事件被多次触发

我对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次)时,会发生错误 . 帮助仍将受到赞赏 .

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值