gpt4 book ai didi

java - Android使用target时的Picasso回调

转载 作者:行者123 更新时间:2023-12-02 09:04:22 25 4
gpt4 key购买 nike

我有一个为 picasso 创建目标的方法,如下所示:

private void createTargets() {
Target target;

for (Id id : itemids) {
target = picassoImageTarget(getContext(), "imageDir", id.getId() + ".png");
imgTargets.add(new ImgTarget(id.getId(), target));
}
}

然后我以这种方式将图像下载到磁盘:

private void download() {
for (ImgTarget imgTarget : imgTargets) {

Picasso.with(getContext()).load("https://www.sestavsisvujsvet.cz/files/magnetky/" + imgTarget.getId() + ".png").into(imgTarget.getTarget());

}
}

它做了我想要它做的事情,但是我无法获得回调,因为带有回调的构造函数仅在使用 ImageView 时才存在:

Ctrl + P

有人可以帮我找到解决方案吗?我不太了解回调之类的东西,所以我很难弄清楚。

我只需要知道整个下载过程何时完成,以便我可以通知用户。

谢谢:)

最佳答案

picasso Target 本质上是一个回调,如果你查看 Target 对象,它具有以下结构:

Target target = new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
// Notify the user
}

@Override
public void onBitmapFailed(Exception e, Drawable errorDrawable) {
// Notify the user
}

@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {

}
};

在您的函数 picassoImageTarget(...) 中,您将构建该目标,并且在 onBitmapLoadedonBitmapFailed 中,您可以将您的根据您的实现编写代码以通知用户。

另外,我注意到您正在使用 Picasso.with(context),这已在最新的库中更新为 Picasso.get(),可能值得更新您的 picasso 库也是最新的。

关于java - Android使用target时的Picasso回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59939265/

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