如何使用 FirebaseUI 显示图像 Firestore RecyclerView.



我想使用 FirebaseUI 和 Firestore 在我的回收器视图中显示图像。到目前为止,我只能显示文本。我无法在网上找到可以理解的解决方案。

正如您在下面的代码中看到的,我已经能够将文本绑定到eventNameeventCity文本视图元素。 有没有办法,也许使用 picasso,使用getDisplay_Image_URI()从 firebase 检索图像 URI 并将其绑定到eventDisplay图像视图?我添加了我正在使用的 POJO 类,以便于理解。

探索页面适配器.java

public class ExplorePageAdapter extends FirestoreRecyclerAdapter<POJO_explore_page_item, ExplorePageAdapter.EventHolder> {
/**
* Create a new RecyclerView adapter that listens to a Firestore Query.  See {@link
* FirestoreRecyclerOptions} for configuration options.
*
* @param options
*/
public ExplorePageAdapter(@NonNull FirestoreRecyclerOptions<POJO_explore_page_item> options) {
super(options);
}
@Override
protected void onBindViewHolder(@NonNull EventHolder eventHolder, int i, @NonNull POJO_explore_page_item pojo_explore_page_item) {
eventHolder.eventName.setText(pojo_explore_page_item.getName());
eventHolder.eventCity.setText(pojo_explore_page_item.getCity());
//eventHolder.eventName.setText(pojo_explore_page_item.getName());
}
@NonNull
@Override
public EventHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.
layout.explore_page_item, parent,false
);
return new EventHolder(v);
}
class EventHolder extends RecyclerView.ViewHolder{
TextView eventName;
TextView eventCity;
ImageView eventDisplay;
//Button bookmark;
public EventHolder(@NonNull View itemView) {
super(itemView);
eventName = itemView.findViewById(R.
id.exp_event_name);
eventCity = itemView.findViewById(R.
id.exp_event_city);
eventDisplay = itemView.findViewById(R.
id.exp_display_image);
//bookmark = itemView.findViewById(R.
//    id.bookmark);
}
}
}

POJO_explore_page_item.java

private String Display_Image_URI;
private String Event_ID;
private String capacity;
private String city;
private String country;
private String deadline;
private String end;
private String start;
private String price;
private String venue;
private String id;
private String name;
public POJO_explore_page_item() {
//empty constructor needed
}
public POJO_explore_page_item(String Display_Image_URI, String Event_ID, String capacity, String city, String country, String deadline, String end, String start, String price, String venue, String id, String name) {
this.Display_Image_URI = Display_Image_URI;
this.Event_ID = Event_ID;
this.capacity = capacity;
this.city = city;
this.country = country;
this.deadline = deadline;
this.end = end;
this.start = start;
this.price = price;
this.venue = venue;
this.id = id;
this.name = name;
}
public String getDisplay_Image_URI() {
return Display_Image_URI;
}
public String getEvent_ID() {
return Event_ID;
}
public String getCapacity() {
return capacity;
}
public String getCity() {
return city;
}
public String getCountry() {
return country;
}
public String getDeadline() {
return deadline;
}
public String getEnd() {
return end;
}
public String getStart() {
return start;
}
public String getPrice() {
return price;
}
public String getVenue() {
return venue;
}
public String getId() {
return id;
}
public String getName() {
return name;
}
}

在你的项目中实现毕加索:

implementation 'com.squareup.picasso:picasso:2.71828'

然后在您的onBindViewHolder中,请确保您提供的图片网址不是 Firebase 图片存储位置:

Picasso.get().load(pojo_explore_page_item.getDisplay_Image_URI()).into(holder.eventDisplay);

您可以使用Glide

添加依赖项

implementation 'com.github.bumptech.glide:glide:4.11.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'

添加此代码来代替图像视图

Glide.with(context).load(url).into(imageView);

您可以使用glide加载图像

Glide.with(your_activity_context).load(pojo_explore_page_item.getDisplay_Image_URI()).placeholder(R.mipmap.placeholder).error(R.mipmap.error).into(holder.eventDisplay);

相关内容

  • 没有找到相关文章

最新更新