Fetch all the userids like this :-
List<String> userIdList = new ArrayList();
DatabaseReference databaseRef = FirebaseDatabase.getInstance().getReference();
databaseRef.child("User").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if(dataSnapshot==null)return;
for (DataSnapshot postSnapshot: dataSnapshot.getChildren()) {
userIdList.add(postSnapShot.getKey());
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
// Error
}
};
Get the address corresponding to any userId
databaseRef.child("Adresses").orderByKey().equalTo(userIdList.get(0)).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if(dataSnapshot==null || dataSnapshot.getChildren()==null || !dataSnapshot.getChildren().iterator().hasNext()){
String address = dataSnapshot.getValue(String.class);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
// Error
}
};