Edittext Validation error message in android?
21,230
Solution 1
I think the way you are showing the error message is better than toast. Sometimes toast duration is too short and the user isn't able to see that.
You can also achieve it by doing this:
EditText et11 = (EditText)findViewById(R.id.username);
if(et11.getText().toString().isEmpty())
{
et11.setError("UserName Should not be blank");
}
Solution 2
private EditText edt_firstName;
private String firstName;
firstName = edt_firstName.getText().toString().trim();
private void validateData(){
firstName = edt_firstName.getText().toString().trim();
if (!firstName.isEmpty(){
//here api call for the login or any other...
} else {
if (firstName.isEmpty()) {
edt_firstName.setError("Please Enter First Name");
edt_firstName.requestFocus();
}
}
}
Author by
Aristo Michael
Having 9+ years of exp. in Android application development. Currently working in Samsung India Electronics Pvt. Ltd.
Updated on July 09, 2022Comments
-
Aristo Michael almost 2 years
In my app i usually show validation error msg like follow :
if(someString.equals("")){ editText.setError("UserName Should not be blank"); }
is there other way to show error message??
i need your suggestion