子对话框打开后关闭父对话框

时间:2014-08-20 05:27:44

标签: android

在我的应用程序中,我正在使用一个"警报对话框"它有三个按钮如下。

单击每个按钮后,将打开一个子对话框。现在我想在点击任何按钮后自动关闭父对话框。      这是我的代码:

final AlertDialog.Builder alertForSelectOperation=new AlertDialog.Builder(DisplayTable_Grid.this); 
            final LinearLayout linear=new LinearLayout(DisplayTable_Grid.this);
            linear.setOrientation(LinearLayout.VERTICAL);

            Button update=(Button)new Button(DisplayTable_Grid.this);
            //update.setBackgroundColor(Color.rgb(3,12,90));
            update.setText(Html.fromHtml("<font size=10>Update</font>"));
            update.setOnClickListener(new OnClickListener()
            {   @Override
    public void onClick(View arg0) 
    {   
                final AlertDialog.Builder alertDialogOK_CANCEL=new AlertDialog.Builder(DisplayTable_Grid.this); 
                final LinearLayout linearlayout=new LinearLayout(DisplayTable_Grid.this);
                linearlayout.setOrientation(LinearLayout.VERTICAL);
                alertDialogOK_CANCEL.setView(linearlayout);
            alertDialogOK_CANCEL.setTitle("insert values here");
            alertDialogOK_CANCEL.create();
            alertDialogOK_CANCEL.show();
            }
    }

Button delete=(Button)new Button(DisplayTable_Grid.this);
delete.setText(Html.fromHtml("<font size=10> Delete</font>"));
delete.setOnClickListener(new OnClickListener()
            {   
                @Override
    public void onClick(View arg0) 
    {
                final AlertDialog.Builder alertDialogOK_CANCEL=new AlertDialog.Builder(DisplayTable_Grid.this); 
                alertDialogOK_CANCEL.setMessage("Press OK to Delete this Record");
                alertDialogOK_CANCEL.setPositiveButton("OK", new DialogInterface.OnClickListener()
                {   @Override
            public void onClick(DialogInterface arg0, int arg1)
        }
        });

                alertDialogOK_CANCEL.setNegativeButton("CANCEL",new DialogInterface.OnClickListener()
                {   @Override
                public void onClick(DialogInterface dialog, int arg1)
                {
                        dialog.dismiss();
                }
        });
                alertDialogOK_CANCEL.create();
                alertDialogOK_CANCEL.show();
    }
    });

1 个答案:

答案 0 :(得分:0)

在您的按钮点击监听器中添加alertForSelectOperation.dismiss();此行,以便在alertDialogOK_CANCEL.show(); and alertDialogOK_CANCEL.show();

之前关闭您的父级警报对话框