I am creating a Sign-Up form.
I have used setError()
to set error messages in all EditText
s. now I want to check that whether an EditText
has error message or not when I click on the submit button.
I am creating a Sign-Up form.
I have used setError()
to set error messages in all EditText
s. now I want to check that whether an EditText
has error message or not when I click on the submit button.
To check text after it has been written but before clicking register/submit button on your page, you need to use TextWatcher
After setting up error with setError()
, you need to check if getError()
returns null
as well as editText.getText().length()
returns 0
then perform action like Toast
or anything.
E.g:
onClick(View v){
if(editText.getError() != null || editText.getText().length() == 0){
................(Perform Toast or something for clearing error)
}else{
.... your action to perform on button click
}
You could use the getError() method for the EditText
and check if it returns null
. Although a better way would be to just set a boolean isValid
on errors and check against that
Right approach to achieve an error less submission of your form will be following:
setError
.you need not to check explicitly if error is set or not as upon next submit field will be re-verified anyways.