I have main RecyclerView which contains other RecyclerViews (let's call them subRecyclerViews). The number of subRecyclerViews is based on the data received from server. The problem is, that whenever a subRecyclerView is about to become visible, it creates ViewHolders for all its items at once (instead of creating ViewHolders only for visible items).
In my MainRecyclerViewAdapter onBindViewHolder() method I call
subRecyclerViewAdapter.setData(data);
subRecyclerView.notifyDataSetChanged();
which results in a lag, because the subRecyclerView is calling onCreateViewHolder() and onBindViewHolder() methods for all its items.
The version of RecyclerView I use is
com.android.support:recyclerview-v7:25.1.1
The question is, is there a way to tell subRecyclerView that it doesn't need to create ViewHolders for the items, that are not yet visible? Also, is this a bug in RecyclerView or am I doing something wrong?