我该如何在appcompact7的alertdialog中进行自定义验证呢?
我在alertdialog中有一些输入,所以当我点击确认按钮时,我想要验证条件是否成立,如果条件不成立,我只想显示错误消息而不关闭对话框。
我尝试了这个,但没有帮助。
alertDialogBuilder
.setCancelable(false)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
if (true) {
// Do this and dissmiss
} else {
// Do not dismiss the dialog
errormsg.setVisibility(View.VISIBLE);
errormsg.setText("Error");
}
}
})
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
28.0.0
与此解决方案完美配合。 - ruX