I have a Sign Up screen with bunch of EditTexts
and each one has a TextWatcher
so I can "listen" for changes and show or hide errors.
For example :
etFirstName.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
if (etFirstName.getText().length() > 0) {
hideFirstNameError();
}
}
});
The problem is that the code is too bloated with all this code being repeated again and again for each one of my editTexts
.
So I was just wondering if there is a cleaner way to write it ? Tried to replace with a custom class that extends TextWatcher
but then I need to pass as variables to the constructor the EditText
s and I'm not so sure if this is a good practice : passing to other classes than your Activities
components that have to do with android ?