What is the difference between the RecyclerView.getChildCount()
and LinearLayoutManager.getItemCount()
?
If I understand correctly the former is the number of views created and being recycled while the later is the number of items in the array backing the recyclerview? I.e. the actual data?
Is this correct?
Asked
Active
Viewed 155 times
1

Jim
- 3,845
- 3
- 22
- 47
1 Answers
1
RecyclerView.getChildCount()
will only return the number of visible views on the screen, not the recycled ones and Yes LinearLayoutManager.getItemCount
will call getItemCount()
of Adapter internally if any adapter is attached and it returns the actual count of items in the data source provided to Adapter.

Rajan Kali
- 12,627
- 3
- 25
- 37
-
Isn't the number of recycled views and visible views roughly the same? – Jim Feb 26 '21 at 12:18
-
@Jim not really, recyclerviews bind a few additional views ahead of what you can see, at least that has been my experience, you can test this out if you'd like by printing when bind gets called – a_local_nobody Feb 26 '21 at 12:31
-
Nope not always, say you rendered list and at page 1 without scrolling, then there will be zero items in recyclerpool. – Rajan Kali Feb 26 '21 at 12:32
-
There are more bound views than visible views, at the very minimum it's visible+1 (since the one ahead (and before) of the visible one, ought to be pre-cached for when you scroll. In practice it's more than that. – Martin Marconcini Feb 26 '21 at 12:47