我有一个问题我是使用Glide从网址加载图片但是如果徽标网址为空则我需要进行验证,然后使用另一个网址来获取图片,但它不起作用我不知道为什么
@Override
public void onBindViewHolder(SearchHorizontalAdapter.ViewHolder holder, int position) {
holder.mTitle.setText(premiumsList.get(position).getName());
if(premiumsList.get(position).getLogo_url_string()==null){
Glide.with(this.activity).load(premiumsList.get(position).getUrl()).into(holder.mImg);
Log.d("",String.valueOf(premiumsList.get(position).getUrl()));
}
else{
Glide.with(this.activity).load(premiumsList.get(position).getLogo_url_string()).into(holder.mImg);
}
}
答案 0 :(得分:1)
你关心小事:
答案 1 :(得分:0)
编辑:请尝试此操作并尽可能提供堆栈跟踪
@Override
public void onBindViewHolder(SearchHorizontalAdapter.ViewHolder holder, int position) {
holder.mTitle.setText(premiumsList.get(position).getName());
if(premiumsList.get(position).getUrl()!=null){
Glide.with(this.activity).load(premiumsList.get(position).getUrl())
.listener(new RequestListener<String, GlideDrawable>() {
@Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
Log.e("IMAGE_EXCEPTION", "Exception " + e.toString());
return false;
}
@Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
Log.d("Sometimes the image is not loaded and this text is not displayed");
return false;
}
})
.into(holder.mImg);
}
else{
Glide.with(this.activity).load(premiumsList.get(position).getLogo_url_string()).into(holder.mImg);
}
}