Populating RecyclerView
So, we added RecyclerView
to our layout. For us to benefit from RecyclerView
, we need to add content to it. Let’s see how we go about doing that.
As we mentioned before, to add content to our RecyclerView
, we would need to implement an adapter. An adapter binds our data to child views. In simpler terms, this means it tells RecyclerView
how to plug data into views designed to present that data.
For example, let’s say we want to present a list of employees.
First, we need to design our UI model. This will be a data object holding all the information needed by our view to present a single employee. Because this is a UI model, one convention is to suffix its name with UiModel
:
data class EmployeeUiModel( val name: String, val biography: String, val role: EmployeeRole, val gender: Gender, val imageUrl: String )
We will...