So I'm trying to display a list of comments under a post in a RecyclerView
. However, I always run into the problem that I can't read the correct value because I don't know how to output the right path when the keys differ.
Can somebody help me?
Here's my structure in Firebase:
Here's my code so far:
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) {
}
});
}