How to listen to Picasso (Android) download events?

Is there a way to listen to events from Picasso when using a builder like:

Picasso.with(getContext()).load(url).into(imageView);

I am trying to call requestLayout() and invalidate() in the parent GridView , so it will be changed correctly, but I do not know how to set the listener or callback.

I see that Picasso has a bug report, but is there a success event?

+81
java android picasso
Oct 24 '14 at 13:16
source share
8 answers

You can use Callback to receive onSuccess and onError events. Just add a new callback to your query as follows:

 Picasso.with(getContext()) .load(url) .into(imageView, new com.squareup.picasso.Callback() { @Override public void onSuccess() { } @Override public void onError() { } }); 

You can then make any changes and modifications to the onSuccess callback.

+241
Oct 24 '14 at 13:30
source share
— -

If you need to access a bitmap before loading it into a view, try using:

 private Target target = new Target() { @Override public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) { } @Override public void onBitmapFailed() { } } 

In the calling method:

 Picasso.with(this).load("url").into(target); 

Ideally, you should implement Target directly on the view or view object.

Hope this helps

+28
Oct 24 '14 at 1:56
source share

The square has recently updated the target class, and now there are more ways to override ( onPrepareLoad and onBitmapFailed ):

 Target target = new Target() { @Override public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) { } @Override public void onBitmapFailed(Drawable errorDrawable) { } @Override public void onPrepareLoad(Drawable placeHolderDrawable) { } }; 

And you still have to use:

 Picasso.with(context).load(url).into(target); 
+6
Sep 29 '15 at 8:40
source share

The answer to the following question is as a comment on MrEngineer13's request (since I do not have enough reputation for comments in any answer), you should use the error() method before registering Callback in into() , for example:

 Picasso.with(getContext()) .load(url) .error(R.drawable.error_placeholder_image) .into(imageView, new com.squareup.picasso.Callback() { @Override public void onSuccess() { //Success image already loaded into the view } @Override public void onError() { //Error placeholder image already loaded into the view, do further handling of this situation here } } ); 
+5
Nov 26 '15 at 12:03
source share
  private final Callback mImageCallback = new Callback() { @Override public void onSuccess() { startPostponedEnterTransition(); } @Override public void onError() { startPostponedEnterTransition(); } }; RequestCreator creator = Picasso.with(getActivity()).load(list.get(position).getId()); creator.into(imageView, mImageCallback); 
+3
May 31 '16 at 11:08
source share

try it

  Picasso.with(context) .load(services.get(position).getImageInactive()) .into(holder.icon, new Callback() { @Override public void onSuccess() { holder.imageLoad.setVisibility(View.GONE); } @Override public void onError() { holder.icon.setImageResource(R.drawable.ic_error_image_load); } }); 
0
Feb 17 '17 at 7:35
source share

In addition to other answers, if you do not know where to use the original image, for example ImageView myIV :

Original:

 Picasso.with(activity).load(url).into(myIV); 

New (inside onBitmapLoaded() new Target() ):

 public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) { myIV.setImageBitmap(bitmap); } 
0
Jun 04 '18 at 21:33
source share

This is loading the image url into the image using picasso simple callbacks

  Picasso.with(this) .load(Picurl) .into(Imageview, new Callback() { @Override public void onSuccess() { } @Override public void onError() { } } ); 

And this is loading the image using picasso with lots of callbacks

 private void loadImage() { Picasso.with(this) .load(PicURL) .into(mContentTarget); } private Target mContentTarget = new Target() { @Override public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) { Imageview.setImageBitmap(bitmap); } @Override public void onBitmapFailed(Drawable errorDrawable) { } @Override public void onPrepareLoad(Drawable placeHolderDrawable) { } }; 
0
Dec 06 '18 at 7:40
source share



All Articles