在第一个对话框中单击按钮显示的第二个对话框关闭第一个对话框 [英] Displaying second dialog from button click in first dialog closes first dialog

查看:300
本文介绍了在第一个对话框中单击按钮显示的第二个对话框关闭第一个对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序,我使用的是 AlertDialog 与自定义视图。这种观点包含了两个的EditText 和其他一些东西的。有附加到执行任何功能所需的的EditText 取值一些听众。

在该对话框的按钮点击,我表演上进入的EditText S中的一些数据验证和显示其他 AlertDialog 如果数据是无效的。一旦(二)对话框关闭,我想留在主对话框(与自定义视图),但由于某种原因,显示我的第二个对话框之前关闭对话框。我怎样才能保持原有的(自定义视图)对话框仍然打开第二个对话框下?

下面是我(简化)code:

 最后EntryPanel面板=新EntryPanel(OrderActivity.this);AlertDialog DLG =新AlertDialog.Builder(OrderActivity.this)
    .setCancelable(真)
    .setView(图)
    .setPositiveButton(R.string.button_ok,新DialogInterface.OnClickListener(){        @覆盖
        公共无效的onClick(DialogInterface对话,诠释它){
            最终诠释ID = pePanel.getProductId();
            如果(!isValidProduct(ID)){                新AlertDialog.Builder(OrderActivity.this)
                    .setMessage(R.string.error_unknown_product)
                    .setCancelable(真)
                    .setPositiveButton(R.string.button_ok,新DialogInterface.OnClickListener(){                        @覆盖
                        公共无效的onClick(DialogInterface DLG2,诠释它){
                            dlg2.cancel();                        }
                    })
                    。显示();
            }
            其他{
                processProductEntry(ID);
                dialog.dismiss();
            }
        }
    })
    .setNegativeButton(R.string.button_cancel,新DialogInterface.OnClickListener(){        @覆盖
        公共无效的onClick(DialogInterface对话,诠释它){
            dialog.cancel();
        }
    })。显示();


解决方案

因此​​,它不可能保持两个对话框打开。因此,我改变了第一个对话框(与自定义视图)要与主题作为一个活动 Theme.Dialog - 它显示该如此 - 然后从中打开第二个对话框。这样,当打开第二个对话框,原来的活动(它看起来像一个对话框)仍然是可见的背景。

In my app, I'm using an AlertDialog with a custom view. This view contains a couple of EditTexts and a few other things. There are some listeners attached to the EditTexts that perform whatever functionality is needed.

On the button click of the dialog, I am performing some validation on the data entered into the EditTexts and display another AlertDialog if the data is invalid. Once that (second) dialog is closed, I want to remain on the main dialog (with the custom view), but for some reason that dialog is closed before my second dialog is shown. How can I keep the original (custom view) dialog still open under the second dialog?

Here's my (simplified) code:

final EntryPanel panel = new EntryPanel(OrderActivity.this);

AlertDialog dlg = new AlertDialog.Builder(OrderActivity.this)
    .setCancelable(true)
    .setView(panel)
    .setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            final int id = pePanel.getProductId();
            if(!isValidProduct(id)) {

                new AlertDialog.Builder(OrderActivity.this)
                    .setMessage(R.string.error_unknown_product)
                    .setCancelable(true)
                    .setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dlg2, int which) {
                            dlg2.cancel();

                        }
                    })
                    .show();
            }
            else {
                processProductEntry(id);
                dialog.dismiss();
            }
        }
    })
    .setNegativeButton(R.string.button_cancel, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    }).show();

解决方案

So, it's not possible to keep both dialogs open. Therefore I changed the first dialog (with the custom view) to be an activity with theme being Theme.Dialog - it displays the way it should - and then open the second dialog from it. This way, when the second dialog is opened, the original activity (which looks like a dialog) is still visible in the background.

这篇关于在第一个对话框中单击按钮显示的第二个对话框关闭第一个对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆