android Progress dialog -> publishProgress method

半世苍凉 提交于 2019-12-13 06:33:55

问题


I'm trying to display 3 different messages in a progress dialog.

In onPreExecute I create the dialog and set the first message.

In doInBackground I call the publishProgres("sentence 2", "sentence 3") with two other sentences/messages that has to be displayed.

If in the onProgressUpdate I use myDialog.setMessage(values[0]); it shows me the first sentence sent and if I use myDialog.setMessage(values[1]); it shows me the second message sent.

But my question is, what can I do to make the dialog display the first sentence sent and after some time the second message?

The hole thing is that I'm ding a connection to an url, doing some other stuff and updating the data of a list at the end and have to display a dialog that shows three different messages while the processes are taking place...


回答1:


publishProgress is invoked to publish updates on the UI thread while the background computation is still running. You can call it during specific intervals to publish the updates, so that the user is informed of the task being run. A typical case is as below:

 protected Void doInBackground(String.. params ) {
     publishProgress("sentence 1");
     //do some time consuming task 
     //..
     publishProgress("sentence 2");
     //do some more time consuming task 
     //..
     publishProgress("sentence 3");
     //do some more time consuming task 
     //..
 }

 protected void onProgressUpdate(String... progress) {
     myDialog.setMessage(progress[0]);
 }

If you have a loop, you can call publishProgress during each or a specific number of iterations.



来源:https://stackoverflow.com/questions/23961605/android-progress-dialog-publishprogress-method

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