if (!validateEmail(email) || (TextUtils.isEmpty(email))) {
emailwrapper.setError("Invalid email");
} else {
emailwrapper.setError(null);
}
if (password.length() < 6 || (TextUtils.isEmpty(password))) {
passwordwrapper.setError("Password must have at least 6 characters");
return;
} else {
passwordwrapper.setError(null);
}
startActivity(new Intent(SignupActivity.this, MoreInfo.class));
How would I make it so that both error messages display if the two Text Input Layouts are left blank and make sure that the user cannot proceed to the MoreInfo class with only the password filled in correctly?
Create a function, which returns a boolean value and depending on that value proceed accordingly:
private boolean areAllFieldsValid() {
boolean returnValue = true;
if (!validateEmail(email) || (TextUtils.isEmpty(email))) {
emailwrapper.setError("Invalid email");
returnValue = false;
} else {
emailwrapper.setError(null);
}
if (password.length() < 6 || (TextUtils.isEmpty(password))) {
passwordwrapper.setError("Password must have at least 6 characters");
returnValue = false;
} else {
passwordwrapper.setError(null);
}
return returnValue;
}
Now Check this condition using:
if(areAllFieldsValid()){
startActivity(new Intent(SignupActivity.this, MoreInfo.class));
}