0

enter image description here

Now what I am trying to do is to get all user names from all keys.How can I do this??

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

1 Answers1

0

Try the following:

DatabaseReference reference = FirebaseDatabase.getInstance().getReference("users");

reference.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot datas: dataSnapshot.getChildren()){
   String name=datas.child("name").getValue().toString();
    }
 }
  @Override
public void onCancelled(DatabaseError databaseError) {
   }
});

Here you datasnapshot is at users node then you use the for loop to iterate inside the direct children and get the names in your database.

Peter Haddad
  • 78,874
  • 25
  • 140
  • 134