fuadj fuadj - 5 months ago 26
Android Question

EditText valid input indicator

I have a validation for an editText where a user inputs an id. The id has a minimum length of 6 and has error detection. I want to inform the user when a correct id is entered right away. I've searched online and most of what i've found is the case of telling the user of invalid input through methods like

editText.setError()
. So my question is, is there a
setError
equivalent for when the user has done the correct thing.

Answer

You can use the TextChangeListener to perform events when the user changes the text.

textEdit.addTextChangedListener(new TextWatcher() {

   @Override
   public void afterTextChanged(Editable s) {}

   @Override    
   public void beforeTextChanged(CharSequence s, int start,
     int count, int after) {
   }

   @Override    
   public void onTextChanged(CharSequence s, int start,
     int before, int count) {
      // validate text and inform user
   }
});