EditText setError message is not cleared after input

So, I have only the EditText field and a button that, when clicked, launches AsyncTask.

EditText playerName = (EditText)findViewById(R.id.playerEditText); if(playerName.getText().toString().length() == 0 ) playerName.setError("Player name is required!"); else { // do async task } 

The problem is that the error message does not seem to work even after entering the correct search text. Is there a way to remove the error once the EditText is empty?

+70
android
Jul 24 '12 at 23:32
source share
6 answers

In the else bracket, put playerName.setError(null) , which will clear the error.

+129
Jul 24 2018-12-12T00:
source share

API documentation: "The icon and error message will be reset to zero if any key events cause changes to the TextView text." Although this is not so, and therefore we can consider this a mistake.

If you use inputType, for example textNoSuggestions, textEmailAddress, textPassword, the error will be canceled after entering the character. Almost as documented, but again not entirely accurate - the error remains when deleting the character. It seems like a simple workaround with addTextChangedListener and setError (null) can achieve the promised behavior.

In addition, there are reports of the loss of the icon on Android 4.2. Therefore use with caution.

+51
May 11 '14 at 23:56
source share

Try the listener:

  playerName.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable edt){ if( playerName.getText().length()>0) { playerName.setError(null); } } 
+12
Jul 18 '14 at 15:29
source share

If you want to hide the error message in one way, you will use onclicklistener in the edit box and then

 editTextName.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub editTextName.setError(Null) } }); 
+3
Apr 15 '15 at 12:34
source share

Below code worked for me

 @OnTextChanged( value = R.id.editTextName, callback = OnTextChanged.Callback.TEXT_CHANGED) public void afterInput(CharSequence sequence) { editTextName.setError(null); editTextName.setErrorEnabled(false); } 

''

editTextName.setError(null) error message.

editTextName.setErrorEnabled(false) extra indent.

+1
May 18 '18 at 9:28
source share

Add a TextWatcher to your EditText and onError, show your error message using et.setError(errorMessage) otherwise you can delete the error message and the error icon like et.setError(errorMessage) below.

 // to remove the error message in your EditText et.setError(null); // to remove the error icon from EditText. et.setCompoundDrawables(null, null, null, null); 
0
Apr 09 '19 at 14:07 on
source share



All Articles