This may also help someone
First Use
recyclerView.setAdapter(adapter);
And then:
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
So it will look like this:
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
The order is reversed
Update:
Nowadays I simply use:
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
on the RecyclerView
in the xml