firebase访问子节点和孙子节点android

时间:2018-01-26 03:30:26

标签: android firebase firebase-realtime-database

解决

Android - Firebase - Getting Child of Child Data

如何查看子节点和孙子节点

E / data:{6640 = {first = {sub3 = dbms,m5 = 3,m2 = 2,sub2 = dl,sub1 = cis,m3 = 2,sub4 = socio,m4 = 2,sub5 = english, M1 = 4}}}

firebase data structure

我想要的值是

  1. 6640内的孩子,例如:第一和第二
  2. 孙子里面的第一个例如:sub1 - sub5和m1-m5
  3. 上面的数据是来自查询的快照数据快照..我如何从以下快照访问每个值..我创建了一个数据模块,并为每个循环使用了这样的

     for (DataSnapshot post : dataSnapshot.getChildren())
         {
          trial_module m2 = post.getValue(trial_module.class);
          Log.e("data",dataSnapshot.getValue().toString());
          data2.add(m2);
          }
    

    我是否需要创建多个类来保存数据?

    public class Result_module {
        String sub1,sub2,sub3,sub4,sub5;
        long m1,m2,m3,m4,m5;
    
    
        public String getSub1() {
            return sub1;
        }
    
        public void setSub1(String sub1) {
            this.sub1 = sub1;
        }
    
        public String getSub2() {
            return sub2;
        }
    
        public void setSub2(String sub2) {
            this.sub2 = sub2;
        }
    
        public String getSub3() {
            return sub3;
        }
    
        public void setSub3(String sub3) {
            this.sub3 = sub3;
        }
    
        public String getSub4() {
            return sub4;
        }
    
        public void setSub4(String sub4) {
            this.sub4 = sub4;
        }
    
        public String getSub5() {
            return sub5;
        }
    
        public void setSub5(String sub5) {
            this.sub5 = sub5;
        }
    
        public long getM1() {
            return m1;
        }
    
        public void setM1(long m1) {
            this.m1 = m1;
        }
    
        public long getM2() {
            return m2;
        }
    
        public void setM2(long m2) {
            this.m2 = m2;
        }
    
        public long getM3() {
            return m3;
        }
    
        public void setM3(long m3) {
            this.m3 = m3;
        }
    
        public long getM4() {
            return m4;
        }
    
        public void setM4(long m4) {
            this.m4 = m4;
        }
    
        public long getM5() {
            return m5;
        }
    
        public void setM5(long m5) {
            this.m5 = m5;
        }
    }
    

0 个答案:

没有答案