If I have something like:
child name: "value"
How can I get the childname? I know its possible to get the value, but what about the other?
If I have something like:
child name: "value"
How can I get the childname? I know its possible to get the value, but what about the other?
The child name in this situation is the "KEY" of that value. So use the reference object and call getKey() on it.
String name = ref.getKey();
Try this.
var ref = firebase.database().ref("root/childName");
ref.once("value")
.then(function(snapshot) {
var key = snapshot.key; // "childName";
});
[UPDATED]
Sorry I posted for javascript.
get all child:
dbRef.child("tipo_arte").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
item.clear();
item.add("");
for (DataSnapshot child : dataSnapshot.getChildren()) {
item.add(child.getKey()); //Pega o nome de cada tipo de arte
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});