-1
我想禁用警报对话框关闭,如果TextView是空的,我经历了几个帖子,但没有他们是自定义警报对话框。 如何解决这个问题。由于提前 这里是我的代码示例定制警告对话框代码如何禁用警报对话框关闭,如果在警报对话框中的editText为空
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);
}
你检查[这](HTTP://计算器。 com/questions/26086848/android-dont-dismiss-alertdialog-after-click-positivebutton) –
现在查看我的答案。 –
谢谢所有,我跟着@kishire Jethava的建议,为我工作 – Andi