【问题标题】:How to call showDialog(i) from showDialog(i)? (Android)如何从 showDialog(i) 调用 showDialog(i)? (安卓)
【发布时间】: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


    【解决方案1】:

    这里是讨论:Dialog.show() vs. Activity.showDialog()

    请看那个...

    希望对您有所帮助。 :)

    【讨论】:

    • 所以在这种特殊情况下,有必要替换'AlertDialog.Builder builder = new AlertDialog.Builder(this);' 'final AlertDialog.Builder builder = new AlertDialog.Builder(this);'和'showDialog(0);'用'builder.create().show();'。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-30
    • 1970-01-01
    • 2021-01-23
    • 2013-08-06
    相关资源
    最近更新 更多