TextInputLayout not showing error message after clearing

大城市里の小女人 提交于 2019-12-10 13:14:59

问题


I am using TextInputLayout from com.android.support:design:23.3.0

When I first apply an error it is shown correctly.

mInputPassword.setError(getString(R.string.error_invalid_password));
mInputEmail.setError(getString(R.string.error_field_required));

On the next login attempt I clear the error.

mInputEmail.setError(null);
mInputPassword.setError(null);

Then I run the validation and set the error again using the same code as above but this time the red line is applied but the error text is missing.

Anyone have any ideas on why this might be happening or have experienced similar situations?

I saw something similar reported here but it is for an older version of the design library and don't know if it is still a issue in the verison I am using,


回答1:


You simply has to do these steps:

setErrorEnabled(true);
setError("error");

for clearing:

setError(null);
setErrorEnabled(false);

repeat the first step to set a new error. setError(null) clears the error message and icon, so I think the view to show is simply gone and setErrorEnabled(false) will reset it.




回答2:


You are clearing the Error Message String:

mInputEmail.setError(null);
mInputPassword.setError(null);

So when you rerun the validation, you will get a blank string.

If you want the error message to go away, clear the erroneous text from the textview:

mInputEmail.setText("");
mInputPassword.setText("");


来源:https://stackoverflow.com/questions/36912602/textinputlayout-not-showing-error-message-after-clearing

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