我需要在扁平的firebase结构中导航并获取数据并为回收者视图充电
这是firebase的示例结构
Report.json结构:
{
"time_stamp_id_report": {
"description": "uma descrição aqui",
"title": "Um titulo aqui"
}
}
这是我的适配器
FirebaseRecyclerAdapter<Report, ViewHolderReport> adapter = new FirebaseRecyclerAdapter<Report, ViewHolderReport>(Report.class,
R.layout.layout_report_card_list, ViewHolderReport.class, ref) {
@Override
protected void populateViewHolder(ViewHolderReport viewHolderReport, Report r, int i) {
viewHolderReport.nameReport.setText(r.getTitle());
}
};
工作正常。但现在我有这种扁平的结构:
Report.json结构
{
"time_stamp_id_report": {
"description": "uma descrição aqui",
"image": {
"image1": true,
"image2 ": true
},
"title": "Um titulo aqui"
}
}
Images.json结构
{
"image1": {
"value": "qiwuhqweouhfqwofe"
},
"image2": {
"image": "quwerhqiweurqhwieurqhwei"
}
}
那么,如何在报告适配器中获取图像值?
答案 0 :(得分:1)
将报告类更改为此类
public class TimeStampIdReport {
private String description;
private Image image;
private String title;
public TimeStampIdReport(){
//must have empty contruct to bind the data
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Image getImage() {
return image;
}
public void setImage(Image image) {
this.image = image;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
在 TimeStampIdReport 类的内部或外部添加Image类,如下所示
public class Image {
private Boolean image1;
private Boolean image2;
public Boolean getImage1() {
return image1;
}
public void setImage1(Boolean image1) {
this.image1 = image1;
}
public Boolean getImage2() {
return image2;
}
public void setImage2(Boolean image2) {
this.image2 = image2;
}
}
根据getImage1()
和getImage2()
方法,您可以通过调用Firebase ref = new Firebase("YOURURL/Images");
来夸大您的观看次数
希望它给你一些想法。