Android : Loading multiple images with Picasso on background

on Wednesday, March 25, 2015


I am trying to get loaded an array of 20 urls in background with Picasso. So far i have the next code:



Log.d("GAME", "Loading all images");
for (int i = gamePieces.length-1; i >= 0; i--) {
GamePiece p = gamePieces[i];
Log.d("GAME", "I will load " + p.getImage());
Picasso.with(context).load(p.getImage()).into(target);
}
//loading the first one
Picasso.with(context).load(piece.getImage()).into(target);


And my target object is the next one:



Target target = new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
Log.d("GAME", "Image loaded" + ++test);
gameImage.setImageBitmap(bitmap); //ImageView to show the images
}

@Override
public void onBitmapFailed(Drawable arg0) {}

@Override
public void onPrepareLoad(Drawable arg0) {}
};


I want to pre load the images so i can show one by one in the ImageView any time the user clicks a button.


The first image is loading so fast(that's cool) but the other images at the for loop never get load. How can i fix this? i need the images to start loading in the for loop.


0 comments:

Post a Comment