How to check if Picasso image is fully loaded

Picasso is asynchronous, so I was wondering if there is a way to check if the image is fully loaded before executing any additional code?

Picasso.with(context).load(imageURI).into(ImageView); // image fully loaded? do something else .. 
+5
source share
2 answers

If the image is fully loaded, it will be installed on the ImageView synchronously.

You can use the callback to confirm this.

 final AtomicBoolean loaded = new AtomicBoolean(); Picasso.with(context).load(imageURI).into(imageView, new Callback.EmptyCallback() { @Override public void onSuccess() { loaded.set(true); } }); if (loaded.get()) { // The image was immediately available. } 
+7
source

Using the overloaded .into(ImageView target, Callback callback) method .into(ImageView target, Callback callback) is suitable for your case. You can use the basic implementation or expand your Base:

 Picasso.with(context).load(url).into(target, new Callback(){ @Override public void onSuccess() { } @Override public void onError() { } }); 

Extended version:

 package main.java.app.picasso.test; /** * Created by nikola on 9/9/14. */ public abstract class TargetCallback implements Callback { private ImageView mTarget; public abstract void onSuccess(ImageView target); public abstract void onError(ImageView target); public TargetCallback(ImageView imageView){ mTarget = imageView; } @Override public void onSuccess() { onSuccess(mTarget); } @Override public void onError() { onError(mTarget); } } 

Using:

 Picasso.with(context).load(url).into(target, new TargetCallback(target) { @Override public void onSuccess(ImageView target) { } @Override public void onError(ImageView target) { } }); 
+6
source

Source: https://habr.com/ru/post/1202167/


All Articles