ProgressDialog dismissal in android

纵饮孤独 提交于 2019-11-30 14:36:37
ingsaurabh

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

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();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!