Android的进度对话框 - > publishProgress方法 [英] android Progress dialog -> publishProgress method

查看:1392
本文介绍了Android的进度对话框 - > publishProgress方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在一个进度对话框中显示3种不同的消息。

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

在上preExecute 我创建对话框,设置第一条消息。

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

doInBackground 我称之为 publishProgres(句2,句3)与其他两句/要显示具有消息

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

如果在 onProgressUpdate 我用 myDialog.setMessage(值[0]); 它让我看到第一句子发送,如果我用 myDialog.setMessage(值[1]); 它为我发来的第二条消息

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?

该洞的事情是,我定到一个URL连接,做一些其他的东西,并在年底更新列表的数据,并有显示一个对话框,显示了三种不同的消息,而过程正在发生。 ..

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...

推荐答案

publishProgress 被调用到UI线程上发布更新,同时后台计算仍在运行。可以在特定的时间间隔称之为发布更新,以便通知用户该任务正在运行的。一个典型的例子是如下:

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

如果你有一个循环,你可以在每个或迭代特定数量的过程中调用 publishProgress

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

这篇关于Android的进度对话框 - > publishProgress方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆