【发布时间】:2019-05-24 06:02:52
【问题描述】:
我有带有根产品的firestore数据库,每个产品都有集合'cmets',所以我在其中存储了所有用户关于这个产品的cmets,但是当查询这个cmets子集合时,我得到空值或零快照火炉
private void getCommentObject(){
query = FirebaseFirestore.getInstance()
.collection("products").document(docID).collection("comments");
FirestoreRecyclerOptions<CommentModel> options = new FirestoreRecyclerOptions.Builder<CommentModel>()
.setQuery(query, CommentModel.class)
.build();
adapter = new FirestoreRecyclerAdapter<CommentModel, commentHolder>(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();
}
这是我的commentModel calss
@IgnoreExtraProperties
公共类 CommentModel 实现可序列化 {
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;
}
}
【问题讨论】:
-
请添加您的
comments集合的结构并确认您已开始监听更改。 -
我添加了 cmets 屏幕截图和评论模型类,是的,我使用代码开始监听 @Override protected void onStart() { super.onStart();适配器.startListening(); } 但在 recyclerview 中获取空值
标签: java android firebase google-cloud-firestore