姬長信(Redy)

java – 如何读取firestore子集合并将其传递…


I有root产品的firestore数据库,每个产品都有集合’comments’,所以我存储了所有用户对这个产品的评论,但是当对这个评论子集合的查询时,我从firestore获得空值或零快照
   private void getCommentObject(){



    query = FirebaseFirestore.getInstance()
            .collection("products").document(docID).collection("comments");

    FirestoreRecyclerOptions options = new FirestoreRecyclerOptions.Builder()
            .setQuery(query, CommentModel.class)
            .build();


    adapter = new FirestoreRecyclerAdapter(options) {
        @NonNull
        @Override
        public commentHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            View view = LayoutInflater.from(parent.getContext())
                    .inflate(R.layout.comment_item_layout, parent, false);

            return new commentHolder(view);
        }

        @Override
        protected void onBindViewHolder(@NonNull commentHolder commentHolder, int position, @NonNull CommentModel commentModel) {


            commentHolder.full_comment.setText(String.valueOf(commentModel.getComment()));
            commentHolder.comment_date.setText(String.valueOf(commentModel.getCommentDate()));
            commentHolder.comment_user.setText(String.valueOf(commentModel.getCommentUser()));


            Glide.with(getApplicationContext())
                    .load(commentModel.getProfilePic())
                    .into(commentHolder.userProfileImg);

        };

    };



    rv.setAdapter(adapter);
    adapter.notifyDataSetChanged();

}

这是我的评论模型

@IgnoreExtraProperties

公共类CommentModel实现Serializable {

public CommentModel() {
}


String comment ,  commentDate , profilePic , commentUser ;

public CommentModel(String comment) {
    this.comment = comment;
}

public String getComment() {
    return this.comment;
}

public void setComment(String Comment) {
    this.comment = comment;
}

public String getCommentDate() {
    return this.commentDate;
}

public void setCommentDate(String commentDate) {
    commentDate = commentDate;
}

public String getProfilePic() {
    return profilePic;
}

public void setProfilePic(String profilePic) {
    this.profilePic = profilePic;
}

public String getCommentUser() {
    return commentUser;
}

public void setCommentUser(String commentUser) {
    commentUser = commentUser;
}

}