我想使用java将数据从firestore云加载到android studio中的listview

我想使用java将数据从firestore云加载到android studio中的listview,java,android,firebase,google-cloud-firestore,Java,Android,Firebase,Google Cloud Firestore,这是我的密码 我在adapater中使用此数组列表在listview中显示 在返回之前,我的arraylist是空的。你们能帮帮我吗 我不知道如何解决您的空列表,但您可以填充您的 在列表中添加项而不是返回 列表,例如: public void loadFromFirebase(){ ArrayList ArrayList=新的ArrayList(); db.collection(“notite”).whereEqualTo(“用户电子邮件”,User.getEmail()) .get().add

这是我的密码 我在adapater中使用此数组列表在listview中显示

在返回之前,我的arraylist是空的。你们能帮帮我吗

我不知道如何解决您的空列表,但您可以填充您的 在列表中添加项而不是返回 列表,例如:

public void loadFromFirebase(){
ArrayList ArrayList=新的ArrayList();
db.collection(“notite”).whereEqualTo(“用户电子邮件”,User.getEmail())
.get().addOnCompleteListener(新的OnCompleteListener()){
@凌驾
未完成的公共void(@NonNull任务){
if(task.issusccessful()&&!task.getResult().isEmpty()){
DocumentSnapshot DocumentSnapshot=task.getResult().getDocuments().get(0);
字符串documentId=documentSnapshot.getId();
db.collection(“notite”).document(documentId.get()
.addOnSuccessListener(新的OnSuccessListener(){
@凌驾
成功时公共无效(文档快照文档快照){
if(documentSnapshot.exists()){
String notita=documentSnapshot.getString(“Detalii”);
arrayList.add(notita);
arrayAdapter=新的arrayAdapter(getContext(),android.R.layout.simple\u list\u item\u 1,
arrayList);
setAdapter(arrayAdapter);
}否则{
Toast.makeText(getContext(),“注释不存在”,
Toast.LENGTH_LONG).show();
}
}
}).addOnFailureListener(新的OnFailureListener(){
@凌驾
public void onFailure(@NonNull异常e){
Toast.makeText(getContext(),“检索失败”,
Toast.LENGTH_LONG).show();
d(“检索”,例如toString());
}
});
}否则{
Toast.makeText(getContext(),“不存在”
,Toast.LENGTH_LONG)show();
}
}
});
}

谢谢你,梅姆!你应该得到一枚奖章;)

Firebase API是异步的。所以,这很可能是因为这解决了我的新问题。谢谢!请在评论部分提及评论。
 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();
                }
            }
        });
        return arrayList;
    }
public void 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);
                                    arrayAdapter = new ArrayAdapter<>(getContext(),android.R.layout.simple_list_item_1,
                                            arrayList);
                                    listView.setAdapter(arrayAdapter);
                                } 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();
            }
        }
    });
}