我无法从数据库下载图像。我的数据库中有两个子节点。我能够成功获取Name的值,但是下载Image时出现问题。这是我的适配器类的代码:-
options = new FirebaseRecyclerOptions.Builder<Category>().setQuery(reference,Category.class).build();
adapter = new FirebaseRecyclerAdapter<Category, MenuViewHolder>(options) {
@Override
protected void onBindViewHolder(@NonNull MenuViewHolder holder, int position, @NonNull Category model) {
Picasso.get().load(model.getImage()).into(holder.img);
holder.txt.setText(model.getName());
}
@NonNull
@Override
public MenuViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.menu_item,parent,false);
return new MenuViewHolder(view);
}
};
adapter.startListening();
recyclerMenu.setAdapter(adapter);
}
型号
public class Category {
private String Name;
private String Image;
public Category() {
}
public Category(String name, String image) {
Name = name;
Image = image;
}
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public String getImage() {
return Image;
}
public void setImage(String image) {
Image = image;
}
答案 0 :(得分:0)
不建议将图像文件存储在实时数据库中。相反,您可以将映像文件存储在Firebase Cloud Storage中,然后通过将文件/路径名称存储在Firebase数据库中进行映射。