Recycling Views

Figure 9.11 shows 11 rows of Views. You can swipe to scroll through 100 Views to see all of your Crimes. Does that mean that you have 100 View objects in memory? Thanks to your RecyclerView, no.

Creating a View for every item in the list all at once could easily become unworkable. As you can imagine, a list can have far more than 100 items, and your list items can be much more involved than your simple implementation here. Also, a Crime only needs a View when it is onscreen, so there is no need to have 100 Views ready and waiting. It would make far more sense to create view objects only as you need them.

RecyclerView does just that. Instead of creating 100 Views, it creates just enough to fill the screen. When a ...

Get Android Programming: The Big Nerd Ranch Guide, 4th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.