【问题标题】:Checking if imageView is empty with Picasso用毕加索检查 imageView 是否为空
【发布时间】:2021-09-03 21:48:50
【问题描述】:

我有数据库表,有一列“image_link”,所以当我打开活动时,毕加索类得到这个 image_link 并向我展示图像。但是现在我的列中也可能有图像路径而不是 imageLink,但无论如何我都需要显示图像,我认为如果我会做这样的事情它会起作用:

@Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        Picasso.get().load(favouriteTemplates.get(position).getImageLink()).into(holder.icon);
        if(holder.icon.getDrawable() == null){
            Picasso.get().load(new File(favouriteTemplates.get(position).getImageLink())).into(holder.icon);
        }
    }

但我知道,使用 Picasso 将图像下载到 imageview 需要一些时间,所以我的“如果”总是正确的。我该如何解决?

【问题讨论】:

  • 在 Picasso 中添加 url 之前简单检查字符串是否为空
  • favouriteTemplates.get(position).getImageLink() 检查这个 url 是否为空
  • 你可以在 into 方法之后使用占位符,你可以写 .placeholder(R.drawable."somephoto you want") 如果你想在发生错误时使用 somephoto,你可以使用它

标签: android picasso


【解决方案1】:
Picasso.get()
   .load(favouriteTemplates.get(position).getImageLink())
   .into(holder.icon),
      new Callback() {
           @Override
           public void onSuccess() {
               //Do Nothing
           }

           @Override
           public void onError(Exception e) {
              Picasso
              .get()
              .load(newmFile(favouriteTemplates.get(position).getImageLink()))
              .into(holder.icon);
           }
      }
   );

【讨论】:

  • 显示来自互联网的图像,但没有来自我的画廊的图像。这是我的图像路径,因为没有调用 inError 方法
猜你喜欢
  • 1970-01-01
  • 2018-12-12
  • 2017-10-14
  • 2021-04-22
  • 2017-05-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多