how the adapter interact with the viewholder : is the viewholder is a template for how the data that passed to the adapter will look in the RecyclerView ? in other word the viewholder is handling the display side of the RecyclerView and how to data will be formatted ?
1 Answers
ViewHolder is a type of helper class that helps us to draw the UI for individual items that we want to draw on the screen.
Ref:https://blog.mindorks.com/how-does-recyclerview-work-internally
So, let us say we have 100 items be displayed on the list and we want to show 5 items on the screen.
Each item here has 1 TextView and 1 ImageView in the item.
SO for 100 elements we would need 100x2 no of findViewByIds if it was without recyclerView
So, when we are using RecyclerView, then only 6 items are created initially with 5 loaded at once to be displayed on-screen and one is the one to be loaded.
Now, if we scroll the list then we have 7 viewHolders. One each for scrapped view and to be loaded view and 5 for the ones which are displayed.
So, at a time, maximum findViewByIds that we are using are only 14 as we have a maximum of 7 ViewHolders.
This efficent management is what make ViewHolder inside recyclerView so efficient

- 4,578
- 3
- 13
- 31