0

四个警报对话框同时出现,我希望在遇到计时器方法时将它们全部删除。我应该怎么办?

 AlertDialog.Builder mainBuilder = new AlertDialog.Builder(AdminViewActivity.this);
                                mainBuilder.setMessage("Table No " +TableList.get(i)+" At Time "+TimeList.get(i))
                               .setPositiveButton("Waiter Called", new DialogInterface.OnClickListener() 
                                {
                                   public void onClick(DialogInterface dialog, int id) {
                                       dailog1=dialog;
                                       dialog.dismiss();       
                                   }
                                });
                                AlertDialog mainAlert = mainBuilder.create();
                                mainAlert.requestWindowFeature(Window.FEATURE_NO_TITLE);
                                WindowManager.LayoutParams WMLP = mainAlert.getWindow().getAttributes();
                                mainAlert.getWindow().getAttributes().gravity = Gravity.LEFT|Gravity.CENTER_VERTICAL;
                                WMLP.x = 10;   //x position
                                WMLP.y = 300;   //y position
                                mainAlert.getWindow().setAttributes(WMLP);
                                mainAlert.show();
4

1 回答 1

1

保存对所有对话框的引用,然后简单地将其关闭:

public class MainActivity extends Activity {
    Dialog mDialog1;
    Dialog mDialog2;
    Dialog mDialog3;
    Dialog mDialog4;

    public void someAction() {
        mDialog1.dismiss();
        mDialog2.dismiss();
        mDialog3.dismiss();
        mDialog4.dismiss();
    }

    public void somewhere() {
        mDialog1 = new dialog();
        mDialog2 = new dialog();
        mDialog3 = new dialog();
        mDialog4 = new dialog();
    }
}
于 2013-06-06T08:38:34.177 回答