Android Question

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 to initialize the lists it does not work in other words the items do not show up

# This is the method

public void InitData(){
DataHolder item1 = new DataHolder();
item1.setEnglish("word in eng");
item1.setGerman("word in ger");

DataHolder item2 = new DataHolder();
item2.setEnglish("word in eng");
item2.setGerman("word in ger");

DataHolder item3 = new DataHolder();
item3.setEnglish("word in eng");
item3.setGerman("word in ger");

DataHolder item4 = new DataHolder();
item4.setEnglish("word in eng");
item4.setGerman("word in ger");

DataHolder item5 = new DataHolder();
item5.setEnglish("word in eng");
item5.setGerman("word in ger");

The Main code

public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.activity_two_fragment, container, false);

rv = (RecyclerView) view.findViewById(;
inputSearch = (EditText) view.findViewById(;

mAdapter = new DataAdapter(list, getContext());

return view;

Answer Source

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(;
//set a vertical layout so the list is displayed top down
final LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);

//initialize the data before binding it to the Adapter
mAdapter = new DataAdapter(list, getContext());

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download