Show Error on the tip of the Edit Text Android

You can show error as PopUp of EditText

if (editText.getText().toString().trim().equalsIgnoreCase("")) {
      editText.setError("This field can not be blank");
}

and that will be look a like as follows

enter image description here

firstName.addTextChangedListener(new TextWatcher()  {

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
    }

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

    @Override
    public void afterTextChanged(Editable s)  {
        if (firstName.getText().toString().length <= 0) {
            firstName.setError("Enter FirstName");
        } else {
            firstName.setError(null);
        }
    }
 });

Leave a Comment