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

Nit*_*mar 5 java ide android apk android-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));
Run Code Online (Sandbox Code Playgroud)

错误行显示在此下

new RequestListener<String, DrawableResource>()

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

错误:类型参数数量错误;需要1

IDE显示以下内容

从RequestListener派生的类匿名类必须声明为抽象或实现方法。

如果我实现IDE推荐的方法,那么我会关注

错误:类型参数数量错误;需要1

Nil*_*hod 11

尝试这个

    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);
Run Code Online (Sandbox Code Playgroud)

  • 工作起来就像一个魅力!谢了哥们。所以 `com.bumptech.glide.load.resource.drawable.GlideDrawable;` 在 Glide 4.7.1 中不再存在!请点赞这个问题。 (2认同)