Now what I am trying to do is to get all user names from all keys.How can I do this??
Asked
Active
Viewed 194 times
1 Answers
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
-
It worked, Thank u so much – Shah Rukh Shahzad Apr 27 '18 at 11:19
-
no problem, happy coding :D – Peter Haddad Apr 27 '18 at 11:20