Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Glide 4.7.1 listener not working for onResourceReady method and Exception listener

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

like image 207
Nithis Kumar Avatar asked Jul 24 '18 11:07

Nithis Kumar


People also ask

How to load image from Glide?

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.

What is placeholder Glide?

Placeholders are Drawables that are shown while a request is in progress.

What is Glide in java?

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.

What is the use of Glide in Android studio?

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.


1 Answers

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);
like image 158
AskNilesh Avatar answered Oct 13 '22 20:10

AskNilesh