I have document in Firestore that has an array of string elements that should referenced to IDs of other documents as well .
so my scenario is to get array of saved IDs from my Firestore then create for loop on it and query on Firestore to get each documents that meets that ID .
but my problem is I'm try to put every result of query to new array but i get only first element
here is my fire-store like :
my code :
void getCoursesDetails(ArrayList<String> openedCourses, MyCallback2 myCallback2){
// Get full details of every course
// openedCourses array here has size of 5
for (int i = 0; i < openedCourses.size(); i++) {
DocumentReference docRef = db.collection("courses").document(openedCourses.get(i));
docRef.get().addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() {
@Override
public void onSuccess(DocumentSnapshot documentSnapshot) {
if (documentSnapshot.exists()) {
detailedCourses.add(documentSnapshot.toObject(Courses.class));
myCallback2.onCallback(detailedCourses);
}
}
});
}
// when put myCallback2.onCallback(detailedCourses); here i get array of zero cuz Firestore loads data asynchronously
}
So my Question is : how to make my array of detailedCourses to save every element that got from for loop round from firestore result ?