Skip to content Skip to sidebar Skip to footer

Android - Recyclerview Data Not Showing Up

I am using one RecyclerView to display two adjacent lists, so far so good but the problem I am facing is : I am storing the data in a public void method but when I call that method

Solution 1:

First add a LayoutManager for the RecyclerView in order to tell it how to display the elements.

Second, I recommend initializate the data first before putting it in the Adapter

rv = (RecyclerView) view.findViewById(R.id.list_view_m);
rv.setHasFixedSize(true);
//set a vertical layout so the list is displayed top downfinalLinearLayoutManagerlayoutManager=newLinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
rv.setLayoutManager(layoutManager);

//initialize the data before binding it to the Adapter
InitData();
mAdapter = newDataAdapter(list, getContext());
rv.setAdapter(mAdapter);

The answer from @Stefan is correct, you use mAdapter.notifyDataSetChanged(); after you have changed the content of the list binded to the RecyclerView, and it would have worked on your code if it had had the LinearLayoutManager in the RecyclerView.

But its better to have a complete (or partial) list before binding it to an Adapter, so the RecyclerView shows the content from the beggining, and after you have changed the elements of the list (add, edit or delete), call the mAdapter.notifyDataSetChanged(); so the RecyclerView updates the display automatically.

Solution 2:

After adding data to your dataset, you should call

adapter.notifyDataSetChanged();

Post a Comment for "Android - Recyclerview Data Not Showing Up"