gpt4 book ai didi

java - Glide 4.7.1 监听器不适用于 onResourceReady 方法和异常监听器

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:01:26 24 4
gpt4 key购买 nike

那里!我正在使用 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);

关于java - Glide 4.7.1 监听器不适用于 onResourceReady 方法和异常监听器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51497808/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com