Мне нужно было это, поэтому я сделал многоразовый ... я расширил класс textwatcher, чтобы я мог передать представление, которое я хочу смотреть.
/**
*
* A TextWatcher which can be reused
*
*/
public class ReusableTextWatcher implements TextWatcher {
private TextView view;
// view represents the view you want to watch. Should inherit from
// TextView
private GenericTextWatcher(View view) {
if (view instanceof TextView)
this.view = (TextView) view;
else
throw new ClassCastException(
"view must be an instance Of TextView");
}
@Override
public void beforeTextChanged(CharSequence charSequence, int i,
int before, int after) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int before,
int count) {
int id = view.getId();
if (id == R.id.someview){
//do the stuff you need to do for this particular view
}
if (id == R.id.someotherview){
//do the stuff you need to do for this other particular view
}
}
@Override
public void afterTextChanged(Editable editable) {
}
}
затем, чтобы использовать его, я делаю что-то вроде этого, чтобы зарегистрировать его:
myEditText.addTextChangedListener(new ReusableTextWatcher(myEditText));