Implementing an Adapter to Populate the RecyclerView

Figure 9.7 is somewhat simplified. RecyclerView does not create ViewHolders itself. Instead, it asks an adapter. An adapter is a controller object that sits between the RecyclerView and the data set that the RecyclerView should display.

The adapter is responsible for:

  • creating the necessary ViewHolders when asked

  • binding ViewHolders to data from the model layer when asked

The recycler view is responsible for:

  • asking the adapter to create a new ViewHolder

  • asking the adapter to bind a ViewHolder to the item from the backing data at a given position

Time to create your adapter. Add a new inner class named CrimeAdapter to CrimeListFragment. Add a primary constructor ...

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.