1
{
"chat_room" : {
"-Kp_ldAz7_g3W4riNkJY" : {
"message" : "Hello!",
"uname" : "Praveen"
}
}
}
这是我的一个聊天信息火力地堡DB JSON文件填充这些,我尝试以下方法,我创建一个名为“appendChat()”来填充数据库在ListView上。如何从火力地堡数据库获取数据,并在ListView
但由于某些原因ListView控件只显示最后一条消息发送
private void appendChat(DataSnapshot dataSnapshot) {
final ArrayList<String> chatListArr = new ArrayList<String>();
Iterator i = dataSnapshot.getChildren().iterator();
while (i.hasNext()) {
chatListArr.add((String) ((DataSnapshot) i.next()).getValue());
chatListArr.add((String) ((DataSnapshot) i.next()).getValue());
}
ArrayAdapter arrayAdapter = new ArrayAdapter(getActivity().getApplicationContext(), android.R.layout.simple_list_item_2,android.R.id.text1, chatListArr);
chatList.setAdapter(arrayAdapter);
}
我的ListView具有用户名和该消息的子字符串的字符串,我如何更改代码检索数据库值和在ListView填充作为
username:
message