AsyncTask的过程中更新UI [英] Updating UI during AsyncTask

查看:209
本文介绍了AsyncTask的过程中更新UI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何从AsyncTask的编辑活动的意见之前,任务就完成了?我无法访问任何从doInBackground方法的意见,我不想等到任务完成。有没有一种方式去这样做呢?还是我来创建doInBackground(这听起来对我来说是不好的做法)中的一个线程,然后访问该线程的完成看法?

How can I edit the views of an activity from an AsyncTask BEFORE the task is complete? I cannot access any of the views from the doInBackground method, and I do not want to wait until the task has completed. Is there a way to go about doing this? Or do I have to create a thread within the doInBackground (which sounds to me would be bad practice) and then access the view on that thread's completion?

推荐答案

重写此方法:

protected void onProgressUpdate(Integer... progress) {
    setProgressPercent(progress[0]);
}

叫它您的AsyncTask的doInBackground()。这种方法 publishProgress(进展...值)

发生在你把它从 doInBackground()

有关更多信息,请阅读的AsyncTask

For more information, read AsyncTask

这篇关于AsyncTask的过程中更新UI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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