简体   繁体   English

如何从Firebase数据库Android获取子节点

[英]How to get child node from Firebase database Android

How can I reference and store the value of this child node?如何引用和存储此子节点的值?

GroupRef = FirebaseDatabase.getInstance().getReference().child("Groups");

I have attempted with String groupAdmin = GroupRef.child("Admin").child("").toString();我尝试过String groupAdmin = GroupRef.child("Admin").child("").toString();

在此处输入图片说明

If you want to get the value of the node under Admin , then do the following:如果要获取Admin下节点的值,请执行以下操作:

DatabaseReference ref = FirebaseDatabase.getInstance().getReference("Groups").child("Baby Names");
ref.child("Admin").addValueEventListener(new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {
         for(DataSnapshot ds : dataSnapshot.getChildren()){
             String key = ds.getValue(String.class);
      }
    }

    @Override
    public void onCancelled(DatabaseError databaseError) {
        throw databaseError.toException();
    }
})

String key = ds.getValue(String.class); this will retrieve the circled key in your question.这将检索您问题中的圆圈键。 You need to know all the nodes before this child to be able to reach it, and then iterate and retrieve the value.您需要知道这个孩子之前的所有节点才能到达它,然后迭代并检索该值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM