简体   繁体   English

Android,如何获取Firebase数据库中自动生成的child identifier?

[英]On Android, how to get the child identifier that was generated automatically in Firebase Database?

The following image shows what I mean:下图显示了我的意思:

How to get the child identifier that was automatically generated in the Firebase Database (which they are shown in the red rectangles), and bring it to Android Studio?如何获取在 Firebase 数据库中自动生成的子标识符(它们显示在红色矩形中),并将其带到 Android Studio?

@Override                    
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
    reference = FirebaseDatabase.getInstance().getReference().child("Usuarios").child(**What must be written here?**); }

You always have to use multiple DatabaseReference objects to approach each nested childs.in your case, it will be something like this to start with.您总是必须使用多个 DatabaseReference 对象来处理每个嵌套的子对象。在您的情况下,开始时会像这样。

 DatabaseReference reference=FirebaseDatabase.getInstance().getReference("Usuarios");
        reference.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot snapshot) {
            
                for(DataSnapshot dataSnapshot: snapshot.getChildren()) {
                  
                      Log.d("TAG", dataSnapshot.getkey());
    reference2 =FirebaseDatabase.getInstance().getReference(dataSnapshot.getkey());
///and so on//
                }
            }
    
            @Override
            public void onCancelled(@NonNull DatabaseError error) {
    
            }
        });

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

相关问题 如何从 Firebase 数据库中获取孩子的数据? - How to get data from a child in Firebase Database? 如何在 firebase android 中获取子数据的子数据 - how to get child of child of child data in firebase android android工作室中firebase的孩子如何获取? - How to get the child from firebase in android studio? 如何在android studio-java的firebase数据库中搜索得到子节点的具体数据? - How to get specific data of child node by searching from firebase database in android studio - java? 如何从 firebase 实时数据库中获取不同孩子的值? - How to get values from different child in firebase realtime database? 如何在 flutter 中实时获取 firebase 数据库中孩子的价值? - how can i get the value of a child in firebase database realtime in flutter? Firebase Realtime Database随机选择子节点后如何获取子节点的key - How to get the key of a child node in Firebase Realtime Database after choosing a child randomly Unity Firebase 实时数据库 - 获取数据库中孩子的索引 - Unity Firebase Realtime Database - Get index of child in database 如何自动将 Firebase 实时数据库写入 Firestore? - How to write Firebase Realtime Database to Firestore automatically? 如何从 Firebase 数据库中获取嵌套的推送密钥 Android - How to get nested push key from Firebase database Android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM