So inside my for loop I am retrieving values from one path and then in the query I am using the creatorUid from the first for loop to get other strings from another path. I need to find a way to be able to retrieve these strings and add them to the arraylist located in the first for loop but not the nested for loop. If you need clarification on what i am talking about i have comments in the code below:
databaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
chatsItemArrayList.clear();
for (DataSnapshot ds : dataSnapshot.getChildren()) {
title = "" + ds.child("title").getValue();
description = "" + ds.child("description").getValue();
date = "" + ds.child("datecreated").getValue();
speaks = "" + ds.child("speaks").getValue();
upvotes = "" + ds.child("upvotes").getValue();
views = "" + ds.child("views").getValue();
picture = "" + ds.child("chatpicture").getValue();
String identifier = "" + ds.child("identifier").getValue();
creatorUid = "" + ds.child("chatcreatoruid").getValue();
System.out.println(creatorUid + " THIS IS THE CREATOR UID");
Query query = FirebaseDatabase.getInstance().getReference().child("Users").orderByKey().equalTo(creatorUid);
query.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot dataSnapshot1 : dataSnapshot.getChildren()) {
//HOW DO I GET THESE VALUES FROM HERE:
rank = "" + dataSnapshot1.child("rank").getValue();
profilePicture = "" + dataSnapshot1.child("image").getValue();
username = "" + dataSnapshot1.child("username").getValue();
System.out.println("THIS IS THE RANK " + getRankText() + " THE USERNAME " + getUsernameText() + " PROFILEPICTURE " + getProfilePicture());
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
System.out.println("R1" + getRankText() + " U1" + getUsernameText() + " P1 " + getProfilePicture());
// TO HERE:
chatsItemArrayList.add(new ChatsItem(getProfilePicture(), title, date, speaks, description, getUsernameText(), getRankText(), upvotes, views, picture));
}
mAdapter = new ChatsFragmentAdapter(chatsItemArrayList);
mRecyclerView.setAdapter(mAdapter);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});