这是我的显示聊天功能,它没有显示任何数据,也没有显示nay错误,请解释什么是错误或错误
private void displayChatMessage() {
ListView l = (ListView) findViewById(R.id.list_of_messages);
Query query = FirebaseDatabase.getInstance().getReference().child("Chat");
FirebaseListOptions<ChatMessage> options = new FirebaseListOptions.Builder<ChatMessage>
().setQuery(query, ChatMessage.class).setLayout(R.layout.list_item).build();
FirebaseListAdapter<ChatMessage> adapter= new FirebaseListAdapter<ChatMessage>(options) {
@Override
protected void populateView (View v, ChatMessage model,int position){
TextView messageText, messageUser, messageTime;
messageText = (TextView) v.findViewById(R.id.message_text);
messageUser = (TextView) v.findViewById(R.id.message_user);
messageTime = (TextView) v.findViewById(R.id.message_time);
messageText.setText(model.getMessageText());
messageUser.setText(model.getMessageUser());
messageTime.setText(DateFormat.format("DD/mm/yyyy (HH:mm:ss)",
model.getMessageTime()));
}
};
l.setAdapter(adapter);
}
}
答案 0 :(得分:0)
您需要使用startListening()
才能开始从Firebase获取数据并显示数据:
要开始填充数据,请调用
startListening()
方法。您可能想在onStart()
方法中调用它。在调用startListening()
之前,请确保已完成读取数据所需的所有身份验证,否则查询将失败。
@Override
protected void onStart() {
super.onStart();
adapter.startListening();
}
https://github.com/firebase/FirebaseUI-Android/blob/master/database/README.md