0

I was creating a method for displaying list items of chat on a listView but due to non-backward compatibly I had to change the code and since then there is an error on listOfMessages.setAdapter(adapter);

There are many edits on the code, so I guess i messed something up ??

  private void displayChatMessages(){
            //ListView listOfMessages = (ListView)findViewById(R.id.list_of_messages);
            Query listOfMessages = FirebaseDatabase.getInstance().getReference().child("chats");
            FirebaseListOptions<ChatMessage> options =
                    new FirebaseListOptions.Builder<ChatMessage>()
                            .setQuery(listOfMessages, ChatMessage.class)
                            .setLayout(android.R.layout.activity_list_item)
                            .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 = (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()));
                }

            };

            listOfMessages.setAdapter(adapter);
        }
  • This link can help you understand better : [https://stackoverflow.com/questions/37580991/how-to-use-firebase-list-adapter](https://stackoverflow.com/questions/37580991/how-to-use-firebase-list-adapter) – mohammad jalili Apr 28 '20 at 18:21

1 Answers1

1

You are setting the adapter to the query, not on the listView:

Instead of this:

listOfMessages.setAdapter(adapter);

Do this:

yourListView.setAdapter(adapter);
Hasan Bou Taam
  • 4,017
  • 2
  • 12
  • 22