Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase List Adapter Constructor error

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);
}
like image 426
dsantali Avatar asked Nov 11 '17 23:11

dsantali


1 Answers

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

like image 149
Peter Haddad Avatar answered Sep 24 '22 14:09

Peter Haddad