how to retrieve all the keys in firebase android

前端 未结 1 1688
执笔经年
执笔经年 2020-12-22 13:46

I want to retrieve all the keys under single key, tried many things, but nothing work till now.

This is my data structure

<

1条回答
  •  时光说笑
    2020-12-22 14:39

    All You have to do is do a nested query .! first find key of parent then get pass that key to next query and then find its children.!

    List userList=new ArrayList();
    
             mdatabaseRef.addValueEventListener(new ValueEventListener() {
          @Override     
          public void onDataChange(DataSnapshot dataSnapshot) {
             for (DataSnapshot child: dataSnapshot.getChildren()){
                String key = child.getKey();
                 fun(key);
                 }
    
          private void fun(String key){
    
            mdatabaseRef.child(key).addValueEventListener(new ValueEventListener() {
           @Override     
           public void onDataChange(DataSnapshot dataSnapshot) {for (DataSnapshot child: dataSnapshot.getChildren()){
        User user= postsnapshot.getValue(User.class);
    userList.add(user);
         }
    
            }
    

    0 讨论(0)
提交回复
热议问题