android – 如何在TextWatcher方法上下文中获取视图?
作者:互联网
我有一个TextWatcher的处理程序,我不知道如何获得已更改文本的视图.
这是我的处理程序:
TextWatcher handler = 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) {
oldText = s.toString();
}
@Override
public void afterTextChanged(Editable s) {
//v.setText("afterTextChanged");
}
};
请注意注释部分,这就是我想要的,从触发事件的EditText获取视图,在文本更改后更改文本.
我怎么能在afterTextChanged事件中找到这个.setText()方法? (像onClick事件,视图是v)
解决方法:
public static class MyTextWatcher implements TextWatcher {
private EditText mEditText;
public MyTextWatcher(EditText editText) {
mEditText = editText;
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
oldText = mEditText.toString();
}
....
}
添加它:
mFirstEditText.addTextChangedListener(new MyTextWatcher(mFirstEditText));
标签:android,events,android-edittext,listener,textwatcher 来源: https://codeday.me/bug/20191007/1867370.html