【问题标题】:ProgressDialog dismissal in androidandroid中的ProgressDialog解雇
【发布时间】:2011-01-20 10:14:22
【问题描述】:

当我单击从 Web 服务打开单击项的数据的列表项时,我想打开一个 ProgressDialog。 ProgressDialog 需要出现,直到被点击的 Item 的 WebContent 被打开。

我知道使用进度对话框的代码,但我不知道如何特别关闭它。

我听说 Handler 将用于关闭进度对话框,但我没有找到任何值得最终使用 Handler 的示例。

谁能告诉我如何使用处理程序来关闭进度对话框?

谢谢, 大卫

【问题讨论】:

    标签: android handler progressdialog


    【解决方案1】:

    你好,这就是你想要的

            public void onClick(View v)
            {
                mDialog = new ProgressDialog(Home.this);
                mDialog.setMessage("Please wait...");
                mDialog.setCancelable(false);
                mDialog.show();
                new Thread(new Runnable()
                {
                    @Override
                    public void run()
                    {
                        statusInquiry();
                    }
                }).start();
            }
    

    这里是被调用的网络服务

    void statusInquiry()
    {
        try
        {
            //calling webservice
                        // after then of whole web part you will send handler a msg
            mHandler.sendEmptyMessage(10);
        }
        catch (Exception e)
        {
            mHandler.sendEmptyMessage(1);
        }
    }
    

    这里是处理程序代码

    Handler mHandler = new Handler()
    {
        public void handleMessage(android.os.Message msg)
        {
            super.handleMessage(msg);
    
            switch (msg.what)
            {
                case 10:
                    mDialog.dismiss();
                    break;
                        }
                 }
          }
     };
    

    【讨论】:

      【解决方案2】:

      解决方案可能是这样的:

      ProgressDialog progressDialog = null;
          // ...
          progressDialog = ProgressDialog.show(this, "Please wait...", true);
          new Thread() {
              public void run() {
                  try{
                        // Grab your data                                                
                  } catch (Exception e) { }
      
                  // When grabbing data is finish: Dismiss your Dialog 
                  progressDialog.dismiss();
              }
         }.start();
      

      【讨论】:

      • 如果在到达progressDialog.dismiss()线之前activity被销毁会导致崩溃
      猜你喜欢
      • 2014-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-18
      • 1970-01-01
      • 1970-01-01
      • 2014-12-18
      • 2023-04-08
      相关资源
      最近更新 更多