简体   繁体   English

在Android中解雇ProgressDialog

[英]ProgressDialog dismissal in android

I want to open a ProgressDialog when I click on the List Item that opens the data of the clicked Item form the Web Service. 当我单击列表项时,我想打开一个ProgressDialog,它打开了Web服务所单击项的数据。 The ProgressDialog needs to be appeared till the WebContent of the clicked Item gets opened. 需要出现ProgressDialog,直到单击的项的WebContent被打开。

I know the code of using the Progress Dialog but I don't know how to dismiss it particularly. 我知道使用Progress Dialog的代码,但我不知道如何解雇它。

I have heard that Handler is to be used for dismissing the Progress Dialog but I didn't found any worth example for using the Handler ultimately. 我听说Handler将用于解雇Progress Dialog,但我没有找到最终使用Handler的任何有价值的例子。

Can anybody please tell me how can I use the Handler to dismiss the Progress Dialog? 任何人都可以告诉我如何使用处理程序来关闭进度对话框?

Thanks, david 谢谢,大卫

Hi this is what you want 嗨,这就是你想要的

        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();
        }

here is the web webservice that is called 这是被调用的web webservice

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);
    }
}

and here goes handler code 这里是处理程序代码

Handler mHandler = new Handler()
{
    public void handleMessage(android.os.Message msg)
    {
        super.handleMessage(msg);

        switch (msg.what)
        {
            case 10:
                mDialog.dismiss();
                break;
                    }
             }
      }
 };

A solutiion could be this: 一个解决方案可能是这样的:

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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM