ProgressDialog dismissal in android

前端 未结 2 1891
别那么骄傲
别那么骄傲 2021-01-02 16:27

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. The ProgressDialog needs to be appeared till the

相关标签:
2条回答
  • 2021-01-02 17:09

    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();
    
    0 讨论(0)
  • 2021-01-02 17:21

    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;
                        }
                 }
          }
     };
    
    0 讨论(0)
提交回复
热议问题