Shumin Shumin - 4 months ago 55x
Android Question

android get Drawable image after picasso loaded

I am using Picasso library to load image from url. The code I used is below.


What I wanna do is to get the image that loaded from url. I used

Drawable image = imageView.getDrawable();

However, this will always return placeholder image instead of the image load from url. Do you guys have any idea? How should I access the drawable image that it's just loaded from url.

Thanks in advance.


This is because the image is loading asynchronously. You need to get the drawable when it is finished loading into the view:

   Target target = new Target() {
          public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
              Drawable image = imageView.getDrawable();

        public void onBitmapFailed(Drawable errorDrawable) {}

        public void onPrepareLoad(Drawable placeHolderDrawable) {}