I have checked high and low but all I see are people trying to to get all the children into lists and stuff. I just want to get a single child from the database.
{
"Haydn" : {
"Users" : {
"email" : "user@gmail.com",
"name" : "kofi"
}
}
}
I want to get the name from the structure.
My code:
rootNode = FirebaseDatabase.getInstance();
reference = rootNode.getReference().child("Users");
reference.addListenerForSingleValueEvent(
new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
if(snapshot.exists()){
String displayName = (String) snapshot.child("Haydn").child("Users").child("name").getValue();
loggedInUserTextView.setText(displayName);
}
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
}