Error in TextInputLayout dont show again even call setErrorEnabled(true)

柔情痞子 提交于 2020-01-07 07:43:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!