
But doing this causes the RecyclerView to flicker, more noticeable if you have images inside your ViewHolders. We often come across a case when we made a few changes to our RecyclerView dataset and want to notify the adapter about the changes by calling notifyDataSetChanged() on the adapter. This can be done by creating a instance of the RecycledViewPool class which is a static class inside RecyclerView and setting the same RecycledViewPool for each of the child RecyclerView by calling tRecycledViewPool(mRecycledViewPool). Many times these child RecyclerViews share common ViewTypes, but each of these Individual RecyclerView creates extra RecycledViews for these common ViewTypes in their own RecycledViewPool because they have no way of knowing that the other RecyclerView already has a RecycledView in memory within it’s RecycledViewPool.Īctually, there is a way to achieve this, by using a common RecycledViewPool for each of these child RecyclerView. One such example can be seen in the Google PlayStore app itself. Nesting Horizontal RecyclerViews inside a Vertical RecyclerView is a very common Design Pattern seen across apps these days. Have a common RecycledViewPool for Nested RecyclerViews This is when we should release resources held by the ViewHolder.

Keep in mind that ViewHolders are recycled so the same ViewHolder will be used with some other Data as well, so better update data each time this function is called.


Initialisation specific things like setting onClickListeners should be done here.

The ViewHolder has it’s own lifecycle that can be used to efficiently provide, update and clean resources related to a particular ViewHolder. This post is not the daily digest that you get on RecyclerView optimisations so do not expect me to put in DiffUtils or setHasFixedSize(). In this blog post, I am going to tell you about a few optimisations and how caching works inside RecyclerView so that you can tweak them at will to get the best out of your Apps. So, knowing little tricks to optimise the performance of this monster in tiny ways is not a bad skill to have. RecyclerView is one of those Widgets that you will use over and over again while developing Android Apps.
