【发布时间】:2012-03-11 02:29:11
【问题描述】:
在我的 Android 应用中,我有一个包含几个选项的对话框,其中一个应该会导致当前对话框再次显示。
是这样的:
protected Dialog onCreateDialog(int id) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
if (id == 0) {
builder.setMessage("Message 0")
.setPositiveButton("Show Message 0 Again", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
showDialog(0);
}
})
.setNegativeButton("Show Message 1", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
showDialog(1);
}
});
} else {
builder.setMessage("Message 1")
.setPositiveButton("Dismiss", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// nothing
}
});
}
AlertDialog dialog = builder.create();
return dialog;
}
但是,当我单击“再次显示消息 0”按钮时,对话框被关闭并且不再出现。 “显示消息 1”按钮工作正常。
如果可能的话,我希望对话框实际上被关闭然后再次打开,而不是简单地让“再次显示消息 0”按钮不做任何事情并且不会导致对话框被关闭。
【问题讨论】:
标签: android android-alertdialog