‫To populate the data in a recycler view, you need to use an adapter.
‫So go to this package, create a new Kotlin class and name it as Sports Adapter.
‫An adapter acts as a bridge between the data source and the recycler view, providing a way to create
‫and bind the views for each item in the data set.
‫Here, inside the primary constructor of this sports adapter, I need to pass val sports list.
‫It's an array list of type sport model.
‫Here.
‫In this example and in this application, our data set and the data source is an array list of type
‫sport model class.
‫Then I need to extend from the recycler view dot adapter class Alt+.
‫Enter to import the Recycler view class from Android X library and dot adapter.
‫And here I need to specify the view holder.
‫Sports adapter extends from Recycler view dot adapter class.
‫It's a generic class parameterized with the type view holder, which is a nested class that you should
‫define within the sports adapter class.
‫The first step is to create the adapter class.
‫The second step is to extend from recycler view adapter class.
‫The third step is to create the inner class inner Viewholder class, and the fourth step is to pass
‫the parameter or the generic type.
‫Here in the Recycler View adapter generic type, I'll start with the inner class, my view holder,
‫and this view holder takes into the constructor item view.
‫It's of type A view Alt+.
‫Enter to import the view class extending from recycler view dot Viewholder class.
‫And here I need to pass the item view.
‫Again.
‫I'll keep it empty because in the next video I'm going to work with the view holder.
‫But now I want from you to understand that my view holder is a static inner class that extends from
‫recycler view dot the view holder class.
‫It holds references to the views within each item.
‫In the recycler view, you will need to define and initialize the views such as text views image views
‫within the item layout.
‫In this class.
‫This is usually done in the init block or directly in the constructor.
‫In the next video, we're going to work with the view holder, but I want from you to follow me exactly
‫in the same order of the steps that I followed.
‫Create the sports adapter.
‫Pass the list in the primary constructor.
‫The third step is to extend from recycler View adapter.
‫The fourth step is to create an inner class that it is of type view holder extending from view holder,
‫and then pass this inner class as a generic type inside this recycler view adapter.
‫So here I'm specifying sports adapter dot my view holder I'm accessing this inner class.
‫You can't directly write like this because it will not find it Alt+.
‫Enter.
‫Change the constructor.
‫Import the class.
‫No.
‫I need to specify to access the inner class.
‫You need to specify the parent class so sports or the outer class sports adapter dot my view holder.
‫Okay, this is how we create the adapter for the recycler view.