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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.