How To Retrieve All The Keys In Firebase Android
I want to retrieve all the keys under single key, tried many things, but nothing work till now. This is my data structure I want to retrieve two keys which are under single key in
Solution 1:
All You have to do is do a nested query .! first find key of parent then get pass that key to next query and then find its children.!
List<user> userList=new ArrayList();
mdatabaseRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot child: dataSnapshot.getChildren()){
String key = child.getKey();
fun(key);
}
private void fun(String key){
mdatabaseRef.child(key).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {for (DataSnapshot child: dataSnapshot.getChildren()){
User user= postsnapshot.getValue(User.class);
userList.add(user);
}
}
Post a Comment for "How To Retrieve All The Keys In Firebase Android"