考虑:
TextView textView = new TextView(context);
textView.addTextChangedListener(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 s) {
s.append("A");
}
});
如果我们添加一个TextWatcher
to a TextView
,我想在此附加一封信TextView
,每次用户在其中写一封信时,但这会不断调用TextWatcher
听众,等等StackOverFlow error
,那么如何在不调用TextWatcher
又是听众?
这很容易:
@Override
public void afterTextChanged(Editable s) {
editText.removeTextChangedListener(this);
//Any modifications at this point will not be detected by TextWatcher,
//so no more StackOverflowError
s.append("A");
editText.addTextChangedListener(this);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)