Here is my code. I use this array list in my adapater for showing in listview
public ArrayList<String> loadFromFirebase() {
ArrayList<String> arrayList = new ArrayList<>();
db.collection("notite").whereEqualTo("User email", user.getEmail())
.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if(task.isSuccessful() && !task.getResult().isEmpty()) {
DocumentSnapshot documentSnapshot = task.getResult().getDocuments().get(0);
String documentId = documentSnapshot.getId();
db.collection("notite").document(documentId).get()
.addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() {
@Override
public void onSuccess(DocumentSnapshot documentSnapshot) {
if(documentSnapshot.exists()) {
String notita = documentSnapshot.getString("Detalii");
arrayList.add(notita);
} else {
Toast.makeText(getContext(), "Notes does not exist",
Toast.LENGTH_LONG).show();
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(getContext(), "Failure retrieving",
Toast.LENGTH_LONG).show();
Log.d("Retrieve", e.toString());
}
});
} else {
Toast.makeText(getContext(), "Does not exist"
, Toast.LENGTH_LONG).show();
}
}
});
right here
return arrayList;
}
Before the return, my arraylist is empty. can you guys help me?