...

/

Updating the RecyclerView

Updating the RecyclerView

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.airports
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import 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 ...