0

I have a RecyclerView that displays a list of messages. When the activity starts the RecyclerView is not populated by the Firebase database. However if I click the back button or an EditText the RecyclerView displays all the items correctly. I have tried manually updating it by using the notifyDataSetChanged method. I have seen other threads, but didn't see anyone with a final solution.

Similar Problem

This is the code called during onStart.

    RecyclerView menu = (RecyclerView) findViewById(R.id.chat_view);

    LinearLayoutManager manager = new LinearLayoutManager(this);
    manager.setReverseLayout(false);

    menu.setAdapter(messageAdapter);
    menu.setLayoutManager(manager);

    messageAdapter.notifyDataSetChanged();`
PleaseNoBugs
  • 169
  • 1
  • 10

2 Answers2

0

That's because you're setting an adapter before setting the layout manager. You should change the order of the 2 lines to this:

    menu.setLayoutManager(manager);
    menu.setAdapter(messageAdapter);
0

you need to use the messageAdapter.notifyDataSetChanged(); inside the indide the firebase request not outside it cause it's asynchrone so firebase doesn't block the main thread until it finish

Oussema Aroua
  • 5,225
  • 1
  • 24
  • 44