there! I'm using glide to load images in my app. Previously I used Picasso and it worked but after migrating to the Glide (v4.7.1) I'm not able to use listener to get state of the resource. I attached code below please help me in this matter.
Glide.with(SlideImageActivity.this)
.load(Constant.arrayList.get(position)
.getImage())
.apply(new RequestOptions()
.placeholder(R.color.colorPrimary)
.dontAnimate().skipMemoryCache(true))
.listener(new RequestListener<String, DrawableResource>() {
public boolean onException(Exception e, String model, Target<DrawableResource> target, boolean isFirstResource) {
spinner.setVisibility(View.GONE);
return false;
}
public boolean onResourceReady(DrawableResource resource, String model, Target<DrawableResource> target, boolean isFromMemoryCache, boolean isFirstResource) {
spinner.setVisibility(View.GONE);
return false;
}
})
.into((ImageView) imageLayout.findViewById(R.id.image));
Error line shows under this
new RequestListener<String, DrawableResource>()
If I try to build apk with this then following error shows
error: wrong number of type arguments; required 1
IDE shows following
Class anonymous class derived from RequestListener must be declard either abstract or implement methods.
if I implement methods which IDE recommends me, I get following
error: wrong number of type arguments; required 1
To simply load an image to LinearLayout, we call the with() method of Glide class and pass the context, then we call the load() method, which contains the URL of the image to be downloaded and finally we call the into() method to display the downloaded image on our ImageView.
Placeholders are Drawables that are shown while a request is in progress.
Glide is a fast and efficient image loading library for Android focused on smooth scrolling. Glide offers an easy to use API, a performant and extensible resource decoding pipeline and automatic resource pooling. Glide supports fetching, decoding, and displaying video stills, images, and animated GIFs.
Glide is an Image Loader Library for Android developed by bumptech and is a library that is recommended by Google. It has been used in many Google open source projects including Google I/O 2014 official application. It provides animated GIF support and handles image loading/caching.
Try this
Glide.with(this)
.load("")
.apply(new RequestOptions()
.placeholder(R.color.colorPrimary)
.dontAnimate().skipMemoryCache(true))
.listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
spinner.setVisibility(View.GONE);
return false;
}
@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
spinner.setVisibility(View.GONE);
return false;
}
})
.into(imageView);
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