问题
I have a TextInputLayout
like this
<android.support.design.widget.TextInputLayout
android:id="@+id/input_layout_name"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/edt_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/title_what_should_we_call_you" />
</android.support.design.widget.TextInputLayout>
For valid name when tap on Submit button I use
private boolean validateName() {
if (edtName.getText().toString().trim().isEmpty()) {
inputLayoutName.setErrorEnabled(true);
inputLayoutName.setError("Enter name");
return false;
} else {
inputLayoutName.setErrorEnabled(false);
}
return true;
}
When I run app, don't enter value to name and tap Submit, the error show (correct).
Then I enter some value to name -> tap Submit -> the error hide (correct)
But then I clear all name -> tap Submit -> the error dont shown
Why it happend? Any help or suggestion would be great appreciated.
If I don't use setErrorEnabled(false);
and just set error message to null, the view of error message still invisible not gone
回答1:
I made a sample to test this and all I had to do was:
if (edtName.getText().toString().trim().isEmpty()) {
inputLayoutName.setError("Enter name");
return false;
} else {
inputLayoutName.setErrorEnabled(false);
}
return true;
The errors reappears as per in your use case should. Can you check with this please?
来源:https://stackoverflow.com/questions/38570339/error-in-textinputlayout-dont-show-again-even-call-seterrorenabledtrue