這是我在firebase中的數據庫結構。如何訪問嵌入在Firebase數據庫中的子節點內的子節點?
我要訪問的消息下的child.I消息內容可以得到數孩子消息的孩子,但不能檢索每個孩子的價值。
ref2
指向我的firebase實例。
我必須從particulat聊天室獲取所有消息。
ref2.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot childDataSnapshot : dataSnapshot.getChildren()) {
listText.add(childDataSnapshot.child("messages").child("message").getValue() + "");
listText.add(childDataSnapshot.child("messages").child("name").getValue() + "");
// userArrayList.add(new User("" + childDataSnapshot.child("username").getValue(), "" + childDataSnapshot.child("profileURL").getValue(), ""));
Log.v("messag_ids", "" + childDataSnapshot.child("messages").child("Kd4TQPrAWsNY1vcid1P").child("message")); //displays the key for the node
}
lvChat.setAdapter(new ChatAdapter(ChatActivity.this, listUsername, listText));
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
發佈您的代碼請 –
代碼更新。 –
您正在使用錯誤的參考。檢查答案。 –