I use glide version 4.7.1 I wanna use default image when onLoadFailed.
this is my code
Glide.with(context).load(imageUrl).listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, com.bumptech.glide.request.target.Target<Drawable> target, boolean isFirstResource) {
// fail
// How can i use default image in imgvAssetPicture?
}
@Override
public boolean onResourceReady(Drawable resource, Object model, com.bumptech.glide.request.target.Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
// success
imgvLoadingProgressbar.setVisibility(View.INVISIBLE);
imgvAssetPicture.setVisibility(View.VISIBLE);
return false;
}
}).into(imgvAssetPicture);
Glide.with(passContext)
.applyDefaultRequestOptions(new RequestOptions()
.placeholder(R.drawable.ic_user_default)
.error(R.drawable.ic_user_default))
.load(url)
.into(image);
With version 4.7.1 (you are using), you can easily set these options.
placeHolder which shows when there is not image.error when some URL fails to load.Bonus
Are you using some ProgressBar with setting visibility, that's very old way to do.
See CircularProgressDrawable, which is very easy to use. Just pass this CircularProgressDrawable in your placeHolder.
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