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?
@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 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) {
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.