‫Welcome back.
‫We created the layouts.
‫We created the data class.
‫Now let's move to the third step which is creating the adapter class.
‫Create a new Kotlin class named as my adapter.
‫Hit enter and inside the primary constructor of this class I'll create Val items list.
‫It's of type array list, and I'll pass the generic type of this array list as item model.
‫This is the name of the class my adapter.
‫And here I am declaring a property inside the primary constructor of this class Val.
‫This keyword declares the property as read only, which is immutable items list.
‫This is the name of the property and array list.
‫This specifies the type of the property items list, indicating that it's an array list containing elements
‫of item model.
‫Again guys, item model is a data class whose main purpose is to hold data back to my adapter.
‫An adapter in a RecyclerView is a class that acts as a bridge between the data source and the RecyclerView
‫UI component.
‫Its primary responsibility is to adapt the data into individual items that can be displayed within the
‫RecyclerView.
‫The adapter is responsible for creating and managing the views for each item in the data set, and it
‫also handles the recycling of views for better performance.
‫Then I need to extend this class from the RecyclerView adapter class.
‫For that, I'll use Recycler view dot adapter Alt+ enter to import the Recycler View class from Android
‫X package.
‫And here I need to pass the view holder data type.
‫I'll skip it now because I'm going to create the view holder at first.
‫So I'll start with the inner class.
‫Don't worry, I'll lecture everything and explain every step.
‫So please just follow me now here I missed the class and I'll create a new inner class called my View
‫Holder.
‫This class will extend from Recycler view dot View holder and inside its primary constructor it took
‫into the parameter item view.
‫It's of type view.
‫And I'm extending from Recycler view view holder.
‫And I'm going to pass the item view.
‫The inner keyword is used to indicate that this class is an inner class, meaning it is nested within
‫another class.
‫And this another class is my adapter.
‫So here when I need to refer to this class, I need to specify the outer class.
‫For example my adapter dot my view holder.
‫So here I am passing the view holder class which is an inner class in this case.
‫So the first step is to extend the from the recycler view adapter.
‫Then to create the inner class view holder then pass inside the generic type.
‫Here the view holder class that you create a view holder is responsible for holding references to the
‫views for a single item.
‫In the recycler view, it helps in efficiently recycling views as the user scrolls through the list.
‫The item view.
‫This is a parameter in the constructor of my view holder.
‫It's responsible for creating a view for a single item in the recycler view.
‫The item view is the root of view of the layout associated with an individual item.
‫My view holder class extends from the recycler view dot the view holder, and takes the item view as
‫a parameter in its constructor.
‫This means that my view holder is a specialized type of view holder tailored for your specific item
‫layout.
‫The view holder is a pattern used in Android's Recycler view to improve performance by recycling views.
‫As the user scrolls through a list, it holds references to the views within a single item layout,
‫so that these views can be efficiently reused when a scroll.
‫As a quick recap, we created this adapter class that extends from RecyclerView dot adapter class.
‫Then we created this inner class which will act as a Viewholder.
‫And then we passed this inner class as a generic type for the RecyclerView dot adapter class.
‫In the next video, we're going to work with the Viewholder class.