I have an alertDialog box that asks the user to enter their full name and email. I am trying to validate the data and if the data is invalid, I would like to display the dialog box again with the error messages (like you do with Edittext fields in android). How would I do that inside the OK button? Here is my code:
final AlertDialog.Builder zoomDialog = new AlertDialog.Builder(new ContextThemeWrapper(activity, android.R.style.Theme_DeviceDefault_Light_Dialog));
LayoutInflater factory = LayoutInflater.from(activity);
final View f = factory.inflate(R.layout.name_and_email, null);
zoomDialog.setTitle("Please enter your name and email");
zoomDialog.setView(f);
zoomDialog.setPositiveButton("SUBMIT", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dlg, int which) {
((onFollowedListener) activity).onFollowed();
EditText full_name = (EditText)f.findViewById(R.id.follower_name);
EditText email_address = (EditText)f.findViewById(R.id.follower_email);
String follower_name = full_name.getText().toString();
String follower_email = email_address.getText().toString();
Validator validator = new Validator();
if(validator.validateFullName(follower_name) && validator.validateEmail(follower_email)){
Toast.makeText(activity, follower_name + " " + follower_email,
Toast.LENGTH_LONG).show();
}else {
full_name.setError("** Required: Please enter your name and email");
full_name.requestFocus();
Toast.makeText(activity, " Please enter your name and email! " ,
Toast.LENGTH_LONG).show();
return;
}
Intent intent = new Intent(activity, RewardActivity.class);
intent.putExtra("type", "followers");
startActivity(intent);
}
});
zoomDialog.show();
Every time I click SUBMIT (POSITIVE) button, the dialog box is dismissed. I would like to keep it open so the user can reenter the information required instead of returning to where they began.
If I could call the show() method inside the else clause, it would be easier but it does not work!
Any help will be highly appreciated. Thanks in advance.