TextInputLayout's errorview is not removed when removing error message

前端 未结 2 1144
青春惊慌失措
青春惊慌失措 2021-01-17 10:24

I have a vertical linear layout with some input fields. Using TextInputLayout I get a nice flow with labels and built-in error messages. My problem is when I add and remove

相关标签:
2条回答
  • 2021-01-17 11:11

    As of Support library version 23.1.1 (and perhaps earlier), this should no longer be the case. You should be able to call TextInputLayout.setErrorEnabled(false) to hide the error TextView and calling TextInputLayout.setError(error) now internally calls TextInputLayout.setErrorEnabled(true) if the error isn't null or empty. See the code snippet below, taken from the support library:

    public void setError(@Nullable CharSequence error) {
        if (!mErrorEnabled) {
            if (TextUtils.isEmpty(error)) {
                // If error isn't enabled, and the error is empty, just return
                return;
            }
            // Else, we'll assume that they want to enable the error functionality
            setErrorEnabled(true);
        }
        ...
    }
    
    0 讨论(0)
  • 2021-01-17 11:11

    For me, below code is working fine.

    @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if(mobileNoInputLayout.isErrorEnabled()){
                mobileNoInputLayout.setErrorEnabled(false);
            }
        }
    
    0 讨论(0)
提交回复
热议问题