在使用FirestoreRecyclerAdapter和nested recyclerview实现评论和回复列表时,可以考虑如下步骤:
下面是示例代码:
Comment类:
public class Comment {
private String commentId;
private String commentText;
//其他属性
public Comment() {}
public Comment(String commentId, String commentText) {
this.commentId = commentId;
this.commentText = commentText;
}
//getter and setter
}
Reply类:
public class Reply {
private String replyId;
private String replyText;
//其他属性
public Reply() {}
public Reply(String replyId, String replyText) {
this.replyId = replyId;
this.replyText = replyText;
}
//getter and setter
}
创建comment集合和reply集合:
FirebaseFirestore db = FirebaseFirestore.getInstance();
CollectionReference commentRef = db.collection("comments");
CollectionReference replyRef = db.collection("replies");
创建FirestoreRecyclerAdapter:
FirestoreRecyclerOptions options = new FirestoreRecyclerOptions.Builder()
.setQuery(commentRef, Comment.class)
.build();
CommentAdapter adapter = new CommentAdapter(options);
commentRecyclerView.setAdapter(adapter);
adapter.startListening();
创建ReplyAdapter和ViewHolder:
public class ReplyAdapter