Java 从云firestore获取?

Java 从云firestore获取?,java,google-cloud-firestore,Java,Google Cloud Firestore,如何从云firestore获取“评论”数据 private void iniRvComment() { DocumentReference docRef = firestore.collection("Comment").document(postKey); docRef.collection("Comment").addSnapshotListener(new EventListener<QuerySnapshot>() { @Override

如何从云firestore获取“评论”数据

private void iniRvComment() {
    DocumentReference docRef = firestore.collection("Comment").document(postKey);
    docRef.collection("Comment").addSnapshotListener(new EventListener<QuerySnapshot>() {
        @Override
        public void onEvent(@Nullable QuerySnapshot documentSnapshot, @Nullable FirebaseFirestoreException e) {
            if (documentSnapshot != null && !documentSnapshot.getDocuments().isEmpty()) {
                listComment = new ArrayList<>();
                List<DocumentSnapshot> documents = documentSnapshot.getDocuments();
                for (DocumentSnapshot value : documents) {

                    Comment comment = value.toObject(Comment.class);
                    listComment.add(comment);
                }
                commentAdapter = new CommentAdapter(getApplicationContext(), listComment);
                RwComment.setAdapter(commentAdapter);
            }
        }
    });
}
private void iniRvComment(){
DocumentReference docRef=firestore.collection(“Comment”).document(postKey);
docRef.collection(“Comment”).addSnapshotListener(新的EventListener(){
@凌驾
public void onEvent(@Nullable QuerySnapshot documentSnapshot,@Nullable FirebaseFirestoreException e){
if(documentSnapshot!=null&&!documentSnapshot.getDocuments().isEmpty()){
listComment=新的ArrayList();
List documents=documentSnapshot.getDocuments();
for(文档快照值:文档){
Comment Comment=value.toObject(Comment.class);
添加(注释);
}
commentAdapter=新的commentAdapter(getApplicationContext(),listComment);
rwcoment.setAdapter(commentAdapter);
}
}
});
}
我使用了Firebase官方网站上的代码,但该代码不起作用,或者我没有正确编写,我使用“postId”作为键。如何获取整个“评论”,以便在每个“帖子”下显示 评论文件:

邮寄文件:


在第一行,您说的是
firestore.collection(“Comment”).document(postId)
,应该是
firestore.collection(“Post”).document(postId)
。不,对不起,已将“postId”改为“postKey”。我想得到“评论”,如果“评论(postKey)==”帖子(postId)“然后我需要在当前postAh下显示评论。。。那么
Comment
是顶级收藏吗?我错过了,是的。你知道怎么做吗?@ArmanAbdullin是
postKey
的值等于
ZQMq。。。7MY2
?请在你说的
firestore.collection(“Comment”).document(postId)
的第一行回复@AlexMamoIn,这应该是
firestore.collection(“Post”).document(postId)
。不,对不起,已将“postId”改为“postKey”。我想获得“评论”,如果“评论(postKey)=“Post(postId)”,那么我需要在当前postAh下显示评论…所以
Comment
是顶级收藏?我错过了。是的。你知道怎么做吗?@ArmanAbdullin是
postKey
的值,等于
ZQMq…7MY2
?请同时回复@AlexMamo