开发者

progress dialog not showing in android?

开发者 https://www.devze.com 2023-03-04 20:28 出处:网络
when does the progress dialog not show in android? i want to know the circumstances when the above can happen:

when does the progress dialog not show in android? i want to know the circumstances when the above can happen:

in my case the progress dialog was not showing in this case:

func{
   开发者_开发技巧 progressdialog.show();
    ....
    .....
    anotherfunction();
    listview.setAdapter();
    progressdialog.dismiss();
   }

what is the general rule of thumb with dialog boxes?

thank you in advance.

EDIT when the .show() command is executed the progress dialog should show. But when the otherfucntion() is called, does the previous command of progressdialog show stop?


Seems like you need to use AsyncTask the UI (including the progressDialog) will not update if the UI thread is still busy. There are many examples in SO for that.

And as a rule of thumb - if you need Progress dialog - you need AsyncTask.

It is not that any command stops, it is just that if you execute a sequence of methods on the UI thread, the UI will probably not be updated until the sequence is over, which is after progressDialog.dismiss(), so the progressDialog should not be displayed anymore.


I think You have to do this in your activity.

ProgressDialog _progressDialog = ProgressDialog.show(this,"Saving Data","Please wait......");
settintAdater();

 private void settingAdater(){

        Thread _thread = new Thread(){

            public void run() {

                Message _msg = new Message();
                _msg.what = 1; 
                 // Do your task where you want to rerieve data to set in adapet
                YourCalss.this._handle.sendMessage(_msg);
            };
        };
        _thread.start();
    }
 Handler _handle = new Handler(){

        public void handleMessage(Message msg) {

            switch(msg.what){

                case 1:
                    _progressDialog.dismiss();
                     listview.setAdapter();
            }
        }
 }


To show a ProgressDialog use

ProgressDialog progressDialog = ProgressDialog.show(PrintMain.this, "", 
                    "Uploading Document. Please wait...", true);

And when you have completed your task use

progressDialog.dismiss();

to dismiss the ProgressDialog ..

You can call to show the ProgressDialog in your onPreExecute method of AsyncTask class and when your done dismiss it in the onPostExecute method

0

精彩评论

暂无评论...
验证码 换一张
取 消