‫Welcome back.
‫Let's continue with the Viewholder class.
‫We said that the Viewholder used for holding references to the views for a single item in the recycler
‫view, and the item view represents the view for a single item in the recycler view.
‫Here inside this class, I'll start initializing the variables that we declare in the layout.
‫VAR item image.
‫It's of type image view.
‫VAR item title.
‫It's of type text view var item description.
‫It's of type text view.
‫Notice that if we go to the item underscore layout, we have three widgets the image view and two text
‫views.
‫I am going to create the references of these UI components inside the inner class.
‫My view holder.
‫Inside this inner class I'll use init block to start initializing these variables.
‫So item image equals to item view, which is the current view representing a view for a single item.
‫In the recycler view dot find view by id r.id dot image view.
‫The item view represents the root view of the individual item in the recycler view.
‫In other words, it's the layout for a single item in the list.
‫And finally view by id.
‫This method is called on the item view to find a view with a specific resource ID, which is the image
‫view I'm referring for this image view of id image view I'll initialize the other two widgets, so item
‫title equals to item view dot find view by id, r.id dot title text and item description equals to item
‫view dot find view by id are.id dot description using a viewholder in a recycler view is a best practice
‫that helps improve the performance of scrolling through a list or grid of items.
‫The primary purpose of the view holder is to hold references to the views within a single item layout,
‫allowing for efficient recycling of views and minimizing the number of views.
‫Creations.
‫During scrolling.
‫Imagine in a recycler view, items are created dynamically as the user scrolls through the list without
‫view recycling, and your view would be created for each item, leading to a significant overhead in
‫terms of memory usage and performance.
‫The solution is using the view holder pattern.
‫The view holder pattern allows views to be recycled.
‫When an item goes off screen, its view holder is recycled and reused for a new item that comes into
‫view.
‫This reduces the number of view creations and helps in keeping the memory footprint low and finding
‫views by their IDs.
‫Using Find View by ID can be expensive operation, especially when performed frequently.
‫The view holder caches references to the views during its creation this way.
‫Subsequent calls to access the views during data binding are faster, as the references are already
‫stored in the view holder, but it's okay to find a view by ID method using the view holder to reduce
‫the find view by id method calls.
‫Scrolling through a large list without a view recycling can result in laggy and inefficient UI performance.
‫The solution comes with the view holder view recycling provided by the Recycler View view holder pattern
‫significantly improves scrolling performance, making it smoother and more responsive, so the view
‫holder pattern helps in achieving efficient view recycling and improves the overall performance of the
‫recycler view.