I created a function to display a chat message, I followed a tutorial, and I also looked at the documentation for the Firebase list adapter, but no matter what I do, I get this error:
Error:(98, 19) error: constructor FirebaseListAdapter in class
FirebaseListAdapter<T> cannot be applied to given types;
required: FirebaseListOptions<ChatMessage>
found: Chat,Class<ChatMessage>,int,DatabaseReference
reason: actual and formal argument lists differ in length
where T is a type-variable:
T extends Object declared in class FirebaseListAdapter
Here is my code:
private void displayChatMessage() {
ListView listOfMessage = (ListView)findViewById(R.id.list_of_messages);
FirebaseRecyclerOptions<ChatMessage> options =
new FirebaseRecyclerOptions.Builder<ChatMessage>()
.setQuery(query, ChatMessage.class)
.build();
adapter = new FirebaseListAdapter<ChatMessage, Holder>(options){
@Override
protected void populateView(View v, ChatMessage model, int position) {
//Get references to the views of list_item.xml
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()));
}
};
listOfMessage.setAdapter(adapter);
}
The below is implied from FirebaseUI version 3.0+
remove this:
adapter = new FirebaseListAdapter<ChatMessage>(this,ChatMessage.class,R.layout.list_item,FirebaseDatabase.getInstance().getReference())
you need to add this:
FirebaseListOptions<ChatMessage> options =
new FirebaseListOptions.Builder<ChatMessage>()
.setQuery(query, ChatMessage.class)
.setLayout(android.R.layout.simple_list_item_1)
.build();
adapter = new FirebaseListAdapter<ChatMessage>(options){
query
is the query that you make for the list adapter example:
Query query = FirebaseDatabase.getInstance().getReference().child("chats");
more information here:
Using FirebaseUI to populate a ListView
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With