I am trying to disable alert dialog close if TextView is Empty,I gone through few posts but non of them are custom Alert Dialog. How to solve this. Thanks in Advance Here is my code sample Custom Alert Dialog code
protected void showInputDialog() {
// get prompts.xml view
LayoutInflater layoutInflater = LayoutInflater.from(Nav_Settings.this);
View promptView = layoutInflater.inflate(R.layout.nav_settings_change_password, null);
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(Nav_Settings.this);
alertDialogBuilder.setView(promptView);
alertDialogBuilder.setIcon(R.drawable.icon_secret);
alertDialogBuilder.setTitle("CHANGE PASSWORD");
final EditText currentPassword = (EditText) promptView.findViewById(R.id.etCurrentPassword);
final EditText newPassword = (EditText) promptView.findViewById(R.id.etNewPassword);
final EditText confirmNewPassword = (EditText) promptView.findViewById(R.id.etConfirmNewPassword);
// setup a dialog window
alertDialogBuilder.setPositiveButton("Update Password", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
if (TextUtils.isEmpty(currentPassword.getText().toString().trim())) {
currentPassword.setError("should not be empty");
} else if (TextUtils.isEmpty(newPassword.getText().toString().trim())) {
newPassword.setError("should not be empty");
} else if (TextUtils.isEmpty(confirmNewPassword.getText().toString().trim())) {
confirmNewPassword.setError("should not be empty");
} else if (newPassword.getText().toString().trim() != confirmNewPassword.getText().toString().trim()) {
confirmNewPassword.setError("new password not matching");
} else if (currentPassword == newPassword) {
newPassword.setError("new password should not be current password");
} else {
Toast.makeText(getApplicationContext(), currentPassword.getText().toString() + "\n" + newPassword.getText().toString() + "\n" + confirmNewPassword.getText().toString(), Toast.LENGTH_SHORT).show();
}
}
}).setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
// create an alert dialog
AlertDialog alert = alertDialogBuilder.create();
alert.show();
alert.getButton(alert.BUTTON_NEGATIVE).setTextColor(getResources().getColor(R.color.colorPrimary));
alert.getButton(alert.BUTTON_POSITIVE).setTextColor(getResources().getColor(R.color.colorPrimary));
Typeface face = Typeface.createFromAsset(getAssets(),
"fonts/RobotoCondensed-Bold.ttf");
alert.getButton(alert.BUTTON_POSITIVE).setTypeface(face);
alert.getButton(alert.BUTTON_NEGATIVE).setTypeface(face);
}