I am making a chat app on Android that uses google firebase to store messages that users write to each other. To display these messages to the users I read them from the database and organize them into a custom ListView with a ListAdapter. This was working fine until I updated my dependencies, specifically firebase ui to:
com.firebaseui:firebase-ui:3.1.0
Now the code to construct the list adapter does not work, being:
adapter = new FirebaseListAdapter<ChatMessage>(FirebaseDatabase.getInstance().getReference("Lobbies").child(leaderID).child("Messages"), ChatMessage.class, R.layout.message, this) {
@Override
protected void populateView(View v, ChatMessage model, int position) {
// Get references to the views of message.xml
TextView messageText = (TextView)v.findViewById(R.id.message_text);
TextView messageUser = (TextView)v.findViewById(R.id.message_user);
TextView messageTime = (TextView)v.findViewById(R.id.message_time);
// Set their text
messageText.setText(model.getMessageText());
messageUser.setText(model.getMessageUser());
// Format the date before showing it
messageTime.setText(DateFormat.format("dd-MM-yyyy (HH:mm:ss)",
model.getMessageTime()));
}
};
To fix this issue, I updated the code to conform to the new firebase ui requirements, making the code become:
FirebaseListOptions<ChatMessage> options = new FirebaseListOptions.Builder<ChatMessage>()
.setQuery(FirebaseDatabase.getInstance().getReference("Lobbies").child(leaderID).child("Messages"), ChatMessage.class).setLayout(R.layout.message).build();
adapter = new FirebaseListAdapter<ChatMessage>(options) {
@Override
protected void populateView(View v, ChatMessage model, int position) {
// Get references to the views of message.xml
TextView messageText = v.findViewById(R.id.message_text);
TextView messageUser = v.findViewById(R.id.message_user);
TextView messageTime = v.findViewById(R.id.message_time);
// Set their text
messageText.setText(model.getMessageText());
messageUser.setText(model.getMessageUser());
// Format the date before showing it
messageTime.setText(DateFormat.format("dd-MM-yyyy (HH:mm:ss)",
model.getMessageTime()));
}
};
This code compiles fine now, but the listview is not displaying the data. Is there a specific right way to use the new firebase ui dependency to make the list adapter?