I am using Picasso for downloading images in my android application. But for some reason my code always downloads only the first image.
Here is my code:
public void setAddresses(String addressesAsString) {
String[] addresses = addressesAsString.split("\n");
addresses[0] = "http://perec.info/wp-content/uploads/perecinfo-panda-1.jpg";
addresses[1] = "http://bessarabiainform.com/wp-content/uploads/2014/10/dinamo_kiev_1680x1050_5693-300x187.jpg";
uris = new Uri[addresses.length];
for (int i = 0; i < addresses.length; ++i) {
uris[i] = Uri.parse(addresses[i]);
}
}
public void downloadAllImages() {
totalDownloaded = 0;
for (Uri uri : uris) {
Target target = new Target() {
@Override
public void onPrepareLoad(Drawable arg0) {
// TODO Auto-generated method stub
}
@Override
public void onBitmapLoaded(Bitmap arg0, LoadedFrom arg1) {
// TODO Auto-generated method stub
processDownloadedImage();
}
@Override
public void onBitmapFailed(Drawable arg0) {
// TODO Auto-generated method stub
processDownloadedImage();
}
void processDownloadedImage() {
totalDownloaded++;
Log.i("Downloaded", "" + totalDownloaded);
if (totalDownloaded == uris.length) {
context.onDownloadingComplete();
}
}
};
Picasso.with(context).load(uri).resize(50, 50).into(target);
}
}
Any ideas why is this happening?
0 comments:
Post a Comment