May 2022
Intermediate to advanced
688 pages
20h 12m
English
The RecyclerView expects an item view to be wrapped in an instance of ViewHolder. A ViewHolder stores a reference to an item’s view. But, as usual, you are not going to interact directly with the View. You are going to use View Binding.
Create a new file named CrimeListAdapter.kt. In it, define a view holder by adding a CrimeHolder class that extends from RecyclerView.ViewHolder.
Listing 10.10 The beginnings of a ViewHolder (CrimeListAdapter.kt)
class CrimeHolder(
val binding: ListItemCrimeBinding
) : RecyclerView.ViewHolder(binding.root) {
}
In CrimeHolder’s constructor, you take in the binding to hold on to. Immediately, you pass its root view as the argument to the RecyclerView.ViewHolder
Read now
Unlock full access