I am trying to load multiple bitmaps from url using Picasso, and draw the bitmaps I load on my google map.
all of this code is in a google MapFragment
.
public void drawLocations(final UserPictureUrl[] userPicsArray) {
for (int j = 0; j < userPicsArray.length; j++) {
Location targetLocation = ... // getting location
// userPicsArray[j].getPicUrl() is the bitmap url
loadProfilePicture(userPicsArray[j].getPicUrl(), targetLocation);
}
}
private void loadProfilePicture(String picUrl, final Location location) {
friendLoadTarget = new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
Toast.makeText(getActivity(), String.valueOf(counter), Toast.LENGTH_SHORT).show();
counter++;
int width = 40;
int height = 40; getResources().getDimension(R.dimen.profile_height);
// drawCanvas draws the bitmap to the map
drawCanvas(location, Bitmap.createScaledBitmap(bitmap, width, height, false), picType);
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
};
Picasso.with(getActivity()).load(picUrl).into(friendLoadTarget);
}
My problem is - I have 3 bitmaps to load, but when running the app, the behavior of the loading is unexpected - sometimes it loads only 1 bitmap, sometimes all 3, sometimes 2 and sometimes none.
As you can see, I put a Toast
to test if the method is actually called, and I almost never get all 3 Toast messages. sometimes only one message with "1" and that's it..
How can make sure all images are loaded properly?