Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading multiple images with Picasso on background

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.

like image 350
Fernando Santiago Avatar asked Mar 25 '15 15:03

Fernando Santiago


Video Answer


1 Answers

I had to use: Picasso.with(getActivity().getApplicationContext()).load(p.getImage()).fetch();

Here is the reference: https://square.github.io/picasso/2.x/picasso/com/squareup/picasso/RequestCreator.html

like image 89
Fernando Santiago Avatar answered Sep 29 '22 11:09

Fernando Santiago