I have firestore database with root products and every products has collection 'comments' so i stored in it all users comments about this product , but when query on this comments sub-collection i get null values or zero snapshots from firestore
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();
}
and here is my commentModel calss
@IgnoreExtraProperties
public class CommentModel implements 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;
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…