I am struggling how to set error for TextInputLayout using library Saripaar. I added TextWatcher for certain inputs that should be validated. I also registered adapter
validator.registerAdapter(TextInputLayout.class,
new ViewDataAdapter<TextInputLayout, String>() {
@Override
public String getData(TextInputLayout flet) throws ConversionException {
return flet.getEditText().getText().toString();
}
}
);
But I am not sure how to set errors for the layout.
@Override
public void onValidationFailed(List<ValidationError> errors) {
for (ValidationError error : errors) {
View view = error.getView();
String message = error.getCollatedErrorMessage(this);
if (view instanceof EditText) {
(EditText)view.setError(message);
} else {
Toast.makeText(this, message, Toast.LENGTH_LONG).show();
}
}
}
Thanks for answers
I changed my code and it is working
First of all I change the bind view to the text input layout
Then I override two methods from the library
The layout has to be clear every time.