如何使用 FirebaseRecyclerViewAdapter 在扁平结构 Firebase 中导航

How to navigate in a flattened structure firebase with FirebaseRecyclerViewAdapter

我需要在扁平化的 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"
  }
}

那么,如何获取报表适配器中的图片值呢?

将您的报告Class改成这样

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 的内部或外部添加图像 class class 像这样

 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");

来扩充视图

希望对你有所启发。