所以我试图在RecyclerView
. 但是,我总是遇到无法读取正确值的问题,因为我不知道如何在键不同时输出正确的路径。
有人可以帮助我吗?
这是我在 Firebase 中的结构:
到目前为止,这是我的代码:
private void loadComments() {
DatabaseReference commentRef = mRootReference.child("comments").child(pollid).getParent().child("comment");
Query commentQuery = commentRef.limitToLast(mCurrentPage * TOTAL_ITEMS_TO_LOAD);
commentQuery.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
for (DataSnapshot ds : dataSnapshot.getChildren()) {
Comment comment = ds.getValue(Comment.class);
commentList.add(comment);
mAdapter.notifyDataSetChanged();
mCommentList.scrollToPosition(commentList.size() - 1);
}
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
慕娘9325324
Cats萌萌
相关分类