Updating the RecyclerView
We'll cover the following...
Creating an adapter
The RecyclerView
uses an adapter to display each row of data. We’ll use a new AirportAdapter
class for this purpose, to display the status of each airport.
Create a new Kotlin class file named AirportAdapter.kt
that will hold the class AirportAdapter
. Let’s start with this initial code for the class in this file:
Press + to interact
package com.agiledeveloper.airportsimport android.support.v7.widget.RecyclerViewimport android.view.LayoutInflaterimport android.view.Viewimport android.view.ViewGroupimport kotlinx.android.synthetic.main.airport_info.view.*class AirportAdapter : RecyclerView.Adapter<AirportViewHolder>() {}class AirportViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {}
An adapter inherits from RecyclerView.Adapter<T>
, where the parametric type T
represents a holder of a view for the data to be displayed. In our implementation, we specialize the parametric type to an AirportViewHolder
. The AirportViewHolder
class, in turn, inherits from RecyclerView.ViewHolder
, which expects an instance ...