如何在显示警报对话框之前禁用按钮,就像在致命对话框中所做的那样“Android错误:应用程序已意外停止,请重试”
。
我用这样的例子:
@Override
protected Dialog onCreateDialog(int id) {
if (id == DIALOG) {
Log.d(LOG_TAG, "Create");
AlertDialog.Builder adb = new AlertDialog.Builder(this);
adb.setTitle("Title");
adb.setMessage("Message");
adb.setPositiveButton("OK", null);
dialog = adb.create();
dialog.setOnShowListener(new OnShowListener() {
public void onShow(DialogInterface dialog) {
Log.d(LOG_TAG, "Show");
}
});
dialog.setOnCancelListener(new OnCancelListener() {
public void onCancel(DialogInterface dialog) {
Log.d(LOG_TAG, "Cancel");
}
});
dialog.setOnDismissListener(new OnDismissListener() {
public void onDismiss(DialogInterface dialog) {
Log.d(LOG_TAG, "Dismiss");
}
});
return dialog;
}
return super.onCreateDialog(id);
}
public void onclick(View v) {
showDialog(DIALOG);
}
如果我在dialog.setOnShowListener上启用按钮,那么用户可以在“确定”按钮上单击两次。
最佳答案
AlertDialog.Builder alertbox = new AlertDialog.Builder(this);
//...All your code to set up the buttons initially
AlertDialog dialog = alertbox.create();
Button button = dialog.getButton(AlertDialog.BUTTON_NEUTRAL);
if(monsterint > playerint)
{
button.setEnabled(false);
}
使用getButton来启用和禁用
关于java - Android AlertDialog 如何在显示之前禁用按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13855951/