嗨,我正在尝试递归下载图像,但我无法。它只下载第一张图片!有人知道为什么吗?
这是我要下载的代码,我做了一个日志来检查我的列表中是否有项目,是的,有 20 个:
Log.d("imageList.size",String.valueOf(imageList.size()));
try
{
for (int i=0; i<=imageList.size(); i++)
{
String image= imageList.get(i);
Log.d("imageList.get(0)",image);
String filename = String.valueOf(image.hashCode());
Log.v("TAG FILE :", filename);
File f = new File(cacheDir, filename);
// Is the bitmap in our cache?
Bitmap bitmap = BitmapFactory.decodeFile(f.getPath());
if (bitmap != null)
return bitmap;
else {
// Nope, have to download it
try {
bitmap = BitmapFactory.decodeStream(new URL(image)
.openConnection().getInputStream());
// save bitmap to cache for later
writeFile(bitmap, f);
return bitmap;
} catch (FileNotFoundException ex) {
ex.printStackTrace();
Log.v("FILE NOT FOUND", "FILE NOT FOUND");
return null;
}
catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
}
}
catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return null;