对此有很多类似的问题,但是某种程度上它对我不起作用。我在Firebase中有数据库,在该数据库中,我有一个类别的子项,而不是另一个子项,即ArrayList。那个孩子被称为“画廊”。画廊的ArrayList为0:图像链接,1:图像链接,依此类推。现在,我想在回收者视图中显示它。我已经有一个代码,但是由于它是一个ArrayList,因此肯定无法正常工作。
屏幕截图:
以下是代码:
Details.java
//comment
recyclerView = (RecyclerView)findViewById(R.id.recyclerComment);
recyclerViewGallery = (RecyclerView) findViewById(R.id.recyclerGallery);
recyclerView.setLayoutManager(newLLM());
recyclerViewGallery.setLayoutManager(newLLM());
private LinearLayoutManager newLLM() {
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
return linearLayoutManager;
}
private void loadGalleryBeach(String menuID) {
Query query = beach.orderByChild("menuID").equalTo(menuID);
FirebaseRecyclerOptions<Gallery> options = new FirebaseRecyclerOptions.Builder<Gallery>()
.setQuery(query, Gallery.class)
.build();
adapter2 = new FirebaseRecyclerAdapter<Gallery, ShowGalleryViewHolder>(options) {
@Override
protected void onBindViewHolder(@NonNull ShowGalleryViewHolder holder, int position, @NonNull Gallery model) {
GalleryImages image = gallery.get(position);
Picasso.get()
.load(image.getImage())
.into(holder.imageView);
}
@NonNull
@Override
public ShowGalleryViewHolder onCreateViewHolder(ViewGroup parent, int i) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.show_gallery_layout, parent, false);
return new ShowGalleryViewHolder(view);
}
};
adapter2.startListening();
recyclerViewGallery.setAdapter(adapter2);
}
ShowGalleryViewHolder
public class ShowGalleryViewHolder extends RecyclerView.ViewHolder {
public ImageView imageView;
public ShowGalleryViewHolder(@NonNull View itemView) {
super(itemView);
imageView = (ImageView)itemView.findViewById(R.id.gallery_image);
}
}
Gallery.java(模型)
public class Gallery {
private List<GalleryImages> gallery;
public Gallery() {
}
public Gallery( List<GalleryImages> gallery) {
this.gallery = gallery;
}
public List<GalleryImages> getGallery() {
return gallery;
}
public void setGallery(List<GalleryImages> gallery) {
this.gallery = gallery;
}
}
GalleryImages.java
public class GalleryImages {
private String image;
public GalleryImages() {
}
public GalleryImages(String image) {
this.image = image;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
}