Adding this
to the listener is jsut optional implementation - basically you need to add an instance of something that is implementing TextWatcher
, and many people tend to do that making the Activity
class implement the interface. However, in your case it might be easier if you have two internal classes implementing the interface in the way you need it.
Basically you can add listeners even with class defined into the addTextChangedListener
method call like that:
editText.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) {
}
});