Skip to content

Instantly share code, notes, and snippets.

@jerrellmardis
Last active May 20, 2019 10:19
Show Gist options
  • Save jerrellmardis/5687856 to your computer and use it in GitHub Desktop.
Save jerrellmardis/5687856 to your computer and use it in GitHub Desktop.
A simple example illustrating how to use Picasso to load a bitmap into a Target. https://github.com/square/picasso
Picasso.with(context).load(url).into(new Target() {
@Override
public void onSuccess(Bitmap bitmap) {
holder.image.setImageBitmap(bitmap);
}
@Override
public void onError() {
// handle
}
});
@nicolaslauquin
Copy link

Methods changed in v2.0.0:

Picasso.with(context).load(url).into(new Target() {

                @Override
                public void onBitmapLoaded(Bitmap bitmap, LoadedFrom arg1) {
                        holder.image.setImageBitmap(bitmap);
                }

                @Override
                public void onBitmapFailed() {

                }
            });

@kartikarora
Copy link

Target will be garbage collected in this case, since Picasso holds a WeakReference to it. Its better to create a data member to hold the reference and not lose it with gc.

https://guides.codepath.com/android/Displaying-Images-with-the-Picasso-Library#adjusting-image-size-dynamically

@uitmasterproject
Copy link

uitmasterproject commented Nov 28, 2017

@kartikarora, Can you help me?
I used to your suggestions, it is good for me.
But, when I have used target in an adapter of Recycler View, this target didn't work in the second element of Recycler View.
Do you have any suggestion for me in this case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment