EditText not clear error message

2019-08-04 04:45发布

问题:

My app is based on the fragments. When i go to the next fragment and return back, than I try to clear my field error message field.setError(null) in onStart() method, but this field have null reference on the error message (field.getError()) . But after onStart() method there appeared reference on the error message. When EditText takes reference on the error message ?

回答1:

Fixed problem with the following method:

 name.post(new Runnable() {
        @Override
        public void run() {
            name.setError(null);
        }
    });

Method post call, when view state has been restored, so all works properly.



回答2:

I met the same problem, but later I refer to the Android Studio automatically generated file, found to have a different way, this way will it setError message is displayed in the EditText last icon, and this error message when you are changing input will automatically disappear.The editText must perform the editText. RequestFocus ();Then execute setError ().