How to listen for Picasso (Android) load complete events?

Keith picture Keith · Oct 24, 2014 · Viewed 48.5k times · Source

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

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

I'm trying to call requestLayout() and invalidate() on the parent GridView so it'll resize properly but I don't know how to set a listener or callback.

I see that Picasso has error event reporting, but is there a success event?

Answer

MrEngineer13 picture MrEngineer13 · Oct 24, 2014

You can use a Callback to get onSuccess and onError events. Just add a new Callback to your request like so:

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

                        }

                        @Override
                        public void onError() {

                        }
                    });

Then you can perform any alterations and modifications in the onSuccess callback.