如何在显示警报对话框之前禁用按钮,就像在 Fatal dialog 上所做的那样"Android error: The application has stopped unexpectedly please try again"
。
我使用这样的例子:
@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 上启用按钮,则用户可以在 OK 按钮上单击两次。