只需单击一下即可关闭所有对话框

时间:2014-11-07 11:51:47

标签: android dialog

我想在点击此按钮时隐藏所有对话框:

new AlertDialog.Builder(FullscreenActivity.this)
                                .setTitle("Error!")
                                .setMessage(".......")
                                .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int which) {
//hide all dialogs
                                        }
                                    }).setIcon(R.drawable.icon_error).show();

我该怎么做?我想用这个关闭所有以前打开的对话框。

1 个答案:

答案 0 :(得分:1)

May this help you.Create common method for calling dialog :

// Declare this as global variables 
    public static AlertDialog.Builder builder;
    public AlertDialog dialog;
    public  Vector<AlertDialog> dialogs = new Vector<AlertDialog>();

public void alertDialog(String message) {
        builder = new AlertDialog.Builder(this);
        builder.setMessage(message).setPositiveButton("OK",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialogs.remove(dialog);
                        dialog.cancel();
                    }
                });
        dialog=builder.create();
        dialogs.add(dialog);
        dialog.show();

    }