本文介绍了如何显示进度当数据从Web加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在执行进度在我的Andr​​oid应用程序。在我的应用程序,我想显示进度条,当图像从网页加载装载机应停止所有图像加载后

I am implementing progressbar in my android app. In my app i want to display progressbar when images are loading from the web after loading all images the loader should be stopped.

我看到进度的一些例子,因为它正在显示的时间predefined周期。但我想进度条显示动态地依赖于从网络装载图像的时间。

I seen some example of progressbar in that it is displaying for predefined period of time. But i want the progressbar display dynamically depends on the time to load images from the web.

推荐答案

您768,16使用的。在Javadoc中有刚,你想要做什么的一个例子:

You shoud use an AsyncTask. The Javadoc for it has an example of just what you want to do :

private class DownloadFilesTask extends AsyncTask<URL, Integer, Long> {
     protected Long doInBackground(URL... urls) {
         int count = urls.length;
         long totalSize = 0;
         for (int i = 0; i < count; i++) {
             totalSize += Downloader.downloadFile(urls[i]);
             publishProgress((int) ((i / (float) count) * 100));
         }
         return totalSize;
     }

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

     protected void onPostExecute(Long result) {
         showDialog("Downloaded " + result + " bytes");
     }
 }

您只需要执行 setProgressPercent 的方法来设置你的进度条,并把它隐藏在 onPostExecute

You just have to implement the setProgressPercent method to set the progress in your progress bar, and hide it on the onPostExecute.

这篇关于如何显示进度当数据从Web加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 16:10