In my android app i have 4 url for one single image. to check if url 1 is broken then go to url 2 and the same way until the end. i using Glide 4.3.1 for loading image like this :
private int checkAndShow4Image(Context context, View view, int img_id, String img_url) {
try {
GlideApp
.with(context)
.load(img_url)
.diskCacheStrategy(DiskCacheStrategy.DATA)
.error(R.drawable.ic_broken_image)
.fallback(R.drawable.ic_broken_image)
.transition(DrawableTransitionOptions.withCrossFade())
.into((ImageView) view.findViewById(img_id));
} catch (Exception e) {
e.printStackTrace();
return -1;
}
return 0;
}
the method is returning before of complete loading. what is the best way for waiting for do it?
Glide use asynchronous way to display the image, try to use a callback to know when the image is completed or failed:
.listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@android.support.annotation.Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
return false;
}
@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
return false;
}
}
)
.into(view);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With