Glide 4.7.1 侦听器不适用于 onResourceReady 方法和异常侦听器

Glide 4.7.1 listener not working for onResourceReady method and Exception listener

有! 我正在使用 glide 在我的应用程序中加载图像。以前我使用 Picasso 并且它工作但是在迁移到 Glide (v4.7.1) 之后我无法使用侦听器来获取资源的状态。我在下面附上了代码,请帮助我解决这个问题。

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));

下方显示错误行

new RequestListener<String, DrawableResource>()

如果我尝试用它构建 apk,则会显示以下错误

error: wrong number of type arguments; required 1

IDE 显示以下

Class anonymous class derived from RequestListener must be declard either abstract or implement methods.

如果我实施 IDE 推荐我的方法,我就会得到关注

error: wrong number of type arguments; required 1

试试这个

    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);