【问题标题】:How to navigate in a flattened structure firebase with FirebaseRecyclerViewAdapter如何使用 FirebaseRecyclerViewAdapter 在扁平结构 Firebase 中导航
【发布时间】:2016-03-19 03:38:08
【问题描述】:

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

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

【问题讨论】:

    标签: android firebase firebase-realtime-database


    【解决方案1】:

    将您的 Report 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 类的内部或外部添加 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"); 来扩充您的视图

    希望能给你一些想法。

    【讨论】:

    • 您好,坦率地说,在我的情况下,我有一些未定义的 imgs。
    猜你喜欢
    • 1970-01-01
    • 2022-01-23
    • 1970-01-01
    • 2022-09-26
    • 2011-11-15
    • 2021-11-19
    • 1970-01-01
    • 2010-10-11
    • 2017-01-07
    相关资源
    最近更新 更多