I made a target of Picasso in a for loop. The first time I receive 1 image and the other images going into the 'onPrepareLoad' statement. The second time I receive all images. Why is it not working the first time?
Code:
final Set<Target> protectedFromGarbageCollectorTargets = new HashSet<>();
for (int i = 0; i < alleFotosArray.size(); i++) {
final Target target = new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
protectedFromGarbageCollectorTargets.remove(this);
int width = bitmap.getWidth();
int height = bitmap.getHeight();
deelnemerSizesFotos sizeFotos = new deelnemerSizesFotos();
sizeFotos.setWidth(width);
sizeFotos.setHeight(height);
sizeFotosArray.add(sizeFotos);
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
protectedFromGarbageCollectorTargets.remove(this);
deelnemerSizesFotos sizeFotos = new deelnemerSizesFotos();
sizeFotos.setWidth(200);
sizeFotos.setHeight(200);
sizeFotosArray.add(sizeFotos);
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
deelnemerSizesFotos sizeFotos = new deelnemerSizesFotos();
sizeFotos.setWidth(200);
sizeFotos.setHeight(200);
sizeFotosArray.add(sizeFotos);
}
};
protectedFromGarbageCollectorTargets.add(target);
Picasso.with(c).load(alleFotosArray.get(i).getImageurl()).into(target);
}