Implementing an Adapter to Populate the RecyclerView

Figure 10.6 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 data to ViewHolders 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 class named CrimeListAdapter in CrimeListAdapter.kt. Add a primary constructor ...

Get Android Programming: The Big Nerd Ranch Guide, 5th 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.