猿问

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

那里!我正在使用 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,则会显示以下错误


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


IDE 显示如下


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


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


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


三国纷争
浏览 737回答 1
1回答

30秒到达战场

试试这个&nbsp; &nbsp; Glide.with(this)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .load("")&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .apply(new RequestOptions()&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .placeholder(R.color.colorPrimary)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .dontAnimate().skipMemoryCache(true))&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .listener(new RequestListener<Drawable>() {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @Override&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; spinner.setVisibility(View.GONE);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return false;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @Override&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; spinner.setVisibility(View.GONE);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return false;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; })&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .into(imageView);
随时随地看视频慕课网APP

相关分类

Java
我要回答