【发布时间】:2011-12-14 13:53:07
【问题描述】:
我正在下载大约 231 张图片,并希望有一个进度对话框说下载图片请等到所有图片都可用然后消失。我该怎么做呢?
protected class DownloadFile extends AsyncTask<String, Integer, String>{
@Override
protected String doInBackground(String... url)
{
int count;
try
{
URL url1 = new URL(url[0]);
URLConnection conexion = url1.openConnection();
conexion.connect();
// this will be useful so that you can show a tipical 0-100% progress bar
int lenghtOfFile = conexion.getContentLength();
// download the file
InputStream input = new BufferedInputStream(url1.openStream());
byte data[] = new byte[1024];
long total = 0;
while ((count = input.read(data)) != -1)
{
total += count;
// publishing the progress....
publishProgress((int)(total*100/lenghtOfFile));
}
input.close();
}
catch (Exception e)
{
}
return null;
}
public void onProgressUpdate(Integer... values)
{
super.onProgressUpdate(values);
// here you will have to update the progressbar
// with something like
setProgress(numPokemon);
}
}
【问题讨论】:
-
请具体说明您面临的问题
-
我有进度对话框出现,但它只在下载一张图片时保持可见,使其无效
-
那你做错了给我们看代码
-
这是您的解决方案检查this 一个。