I had to update support library from 23.1.1 to 23.2.1 because of some bug fixes. However I ran into the problem that after this update call notifyDataSetChange() takes a lot of time and is blocking UI. With short lists like 10-20 items one can not notice difference but with lists of 400-500 items notifyDataSetChange() takes a 2-3 seconds to execute and it is blocking UI. With 23.1.1 I didn't measure how long does it takes, but from user experience update was instant even with lists of 500-600 items.
There was no changes in code, just upgrade to support library from 23.1.1 to 23.2.1.
I tried all 23.2.xx and 23.3.xx and 23.4.xx libraries and all had the same issue. I didn't try it with support libraries 24.xx.xx since I need to use 23 version
I update adapter from my activity asynchronously when i receive myItemList from the network:
...
((MyRecyclerViewAdapter) mAdapter).updateList(myItemList);
...
In adapter I have
public void updateList(List<MyItems> items) {
this.mDataset = items;
notifyDataSetChanged();
}
It did work without delays and blocking UI with 23.1.1 and as I mentioned above it got slow with 23.2.1 and higher. I want to use 23.2.1 because of RecylerView wrap_content functionality was introduced.
Would be appreciated for any help.
My Adapter also has:
public void onBindViewHolder(final ViewHolder holder, int position) {
holder.itemName.setText(mDataset.get(position).getName());
holder.itemPoints.setText(String.valueOf(mDataset.get(position).getPointsNumber()));
}
....
public static class ViewHolder extends RecyclerView.ViewHolder {
public final View mView;
TextView itemName;
TextView itemPoints;
public ViewHolder(View rowView) {
super(rowView);
itemName = (TextView) rowView.findViewById(R.id.item_name);
itemPoints = (TextView) rowView.findViewById(R.id.item_points);
mView = rowView;
}
}
It seems my problem was exactly as described here RecyclerView 23.2.x height=0dp causes onBind called for all items and scrollToPosition not working
As it states in Support Library 23.2+ and higher if one sets layout_height="0dp", onBindViewHolder() is called for all items in the list at once and in my case for lists with 400-600 items it creaated performance problem.
However opposite to suggested solution in link above updating to support library 23.3.0 (or any higher) didn't solve this problem.
To work around the problem I used layout_height="1dp" instead of layout_height="0dp" though for me it is still not clear why this kind of hack works. Or to be more specific why layout_height="0dp" doesn't work as it suppose to.