0

I am trying to dismiss an AlertDialog in android:

    public AlertDialog dialog;
             AlertDialog.Builder builder;
                builder = new AlertDialog.Builder(this);
                builder.setMessage("Message."); 
                dialog= builder.create();
                dialog.show();
  Thread thread = new Thread(this);
  thread.start();

        public void run() {
        Looper.prepare();
        //some code
        handler.sendEmptyMessage(0);
        Looper.loop();
        }

        Handler handler= new Handler() {

            @Override public void handleMessage(Message msg)
            { dialog.dismiss();
            //some code 
            } 
            };

It doesn't work. I have searched and tried several proposed methods, and they were all unsuccessful. Any help is appreciated.

4

1 回答 1

0

请使用 ProgressDailog 而不是警报。

To create:



 ProgressDailog progressDialog = ProgressDialog.show(this,"Loading ..", "Please Wait..");

To dismiss:

progressDialog.dismiss();

取消警报使用下面的代码

dialog.setPositiveButton("ok", null);
        dialog.setCancelable(true);
于 2012-05-02T11:58:35.667 回答