我正在尝试从Firebase检索图像,但是,该图像不是加载在Imageview内,而是以某种方式加载在textView内并显示Firebase存储图像地址,但是,textview甚至没有附加Image
public class AdapterSearch extends RecyclerView.Adapter <AdapterSearch.SearchViewHolder>{
Context context;
ArrayList<String>titlelist;
ArrayList<String>locationlist;
ArrayList<String>imagelist;
ArrayList<String>pricelist;
class SearchViewHolder extends RecyclerView.ViewHolder{
ImageView image;
TextView title,location,price;
public SearchViewHolder(@NonNull View itemView) {
super(itemView);
price=(TextView)itemView.findViewById(R.id.search_event_price);
image=(ImageView) itemView.findViewById(R.id.search_event_img);
title=(TextView)itemView.findViewById(R.id._search_event_title);
location=(TextView)itemView.findViewById(R.id.search_event_location);
}
}
public AdapterSearch(Context context, ArrayList<String> mtitlelist, ArrayList<String> mlocationlist,ArrayList<String> mimagelist, ArrayList<String> mpricelist) {
this.context = context;
this.titlelist = mtitlelist;
this.locationlist = mlocationlist;
this.imagelist = mimagelist;
this.pricelist= mpricelist;
}
@NonNull
@Override
public AdapterSearch.SearchViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View view= LayoutInflater.from(context).inflate(R.layout.search_list,viewGroup,false);
return new AdapterSearch.SearchViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull SearchViewHolder searchViewHolder, int i) {
searchViewHolder.price.setText(pricelist.get(i));
searchViewHolder.title.setText(titlelist.get(i));
searchViewHolder.location.setText(locationlist.get(i));
Glide.with(context).asBitmap().placeholder(R.mipmap.ic_launcher).load(imagelist.get(i)).into(searchViewHolder.image);
searchViewHolder.title.setOnClickListener(new View.OnClickListener() {
答案 0 :(得分:0)
如果未加载图像,请尝试以下代码,检查onException中的错误,然后尝试解决错误
Glide.with(contect)
.load(imagelist.get(i))
.placeholder(R.mipmap.ic_launcher)
.listener(new RequestListener<String, GlideDrawable>() {
@Override
public boolean onException(Exception e, String model, Target<GlideDrawable>
target, boolean isFirstResource) {
return false;
}
@Override
public boolean onResourceReady(GlideDrawable resource, String model,
Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
return false;
}
}).into(searchViewHolder.image);
答案 1 :(得分:0)
imageList.get(i)
中到底是什么?该Firebase存储URI还是下载URL?
可能是原始Glide无法处理存储路径吗?
您可以尝试使用FirebaseUI仅使用Firebase存储路径来使用Glide加载图像,而无需获取下载网址:https://firebase.google.com/docs/storage/android/download-files?authuser=0#downloading_images_with_firebaseui
但是它需要先进行设置:https://github.com/firebase/FirebaseUI-Android/blob/master/storage/README.md