Skip to content Skip to sidebar Skip to footer

How To Show All Edittext Error Messages At Once In Android?

I have two EditTexts and I am applying validations on them. If the validations fail, I want to show all the error messages at once. At a time, I'm getting only one error message wh

Solution 1:

You have to setError(null) in else condition.

if(uname.matches(""))
              username.setError("Email is required");
else
              username.setError(null);

if(pwd.matches(""))
            password.setError("Password is required");
else
              password.setError(null);

Solution 2:

The best approach for using setError is to call it on fields in reverse order, so that the last call is the top-most field in the form. That way all invalid fields will be highlighted but only the top-most field will prompt the User with the error message balloon. The setError mechanism is designed to only show one balloon overlay at a time.

Solution 3:

This will help you

if (TextUtils.isEmpty(username.getText().toString())) {
                    username.setError("ABC");
                }
    else(TextUtils.isEmpty(password.getText().toString())) {
                    password.setError("ABC");
                }

Post a Comment for "How To Show All Edittext Error Messages At Once In Android?"