‫The fourth and fifth step is to create the adapter class and the viewholder.
‫The adapter class holding all methods, dealing with Recyclerview implementation from creating, binding
‫and determining the count of items.
‫The Viewholder holds the references to the views within each item's layout.
‫Optimizing View Lookups.
‫I start creating the custom adapter class and I'll name it as custom adapter.
‫And this class is an adapter class and it's responsible for adapting a list of sports objects into a
‫format that the Recyclerview can display.
‫It manages the process of inflating the item layout, binding data to the views and handling interactions.
‫Let's start by extending it from recycler view dot adapter and you can see VH, which is referred to
‫the view Holder.
‫I need to pass a view holder type here between these two signs, but at first I need to create this
‫view Holder class and I'll name it as sport view holder.
‫So private or public, I make it as public static class sports view holder and this class will extend
‫from the recycler view dot view holder.
‫And you can see that I'm using recycler view class dot view holder and here recycler view dot adapter.
‫This inner static class extends the recycler view that view holder holding the references to the views
‫within the item layout which are found using the item.
‫View dot find view by ID method.
‫This allows efficient recycling of views in recycler view.
‫The custom adapter class acts as a bridge between your data, which is the list of sports objects and
‫the UI components, which is the recycler view and the card view.
‫And our application will receive a list of sport objects and display them into our card view inside
‫the recycler view.
‫So for that, inside the custom adapter, I need to create a list of sport modal class Alt+ enter to
‫import the list and it's named as sport list or sport list.
‫Then I need to create a constructor alt+ insert to create the constructor having this list so this constructor
‫accepts a list of sport modal class.
‫This list is the data that the adapter will display in the recycler view.
‫Now let's implement the methods of the recycler view adapter class Alt+.
‫Enter Implement the methods and we have these three methods.
‫The Oncreate view holder unbind view holder and get item count.
‫I advise you to review the section about the adapters and the list of views in order to understand more
‫what's going on.
‫But I lecture everything.
‫Don't worry, the first method is on Create View Holder.
‫This method is responsible for creating and inflating the layout of each item.
‫In the recycler view, it returns a sports view holder object which holds the references to the views
‫in the item layout.
‫I'll start by defining a view object view item view equal to layout inflator Alt+.
‫Enter to import the view class dot from parent dot get context.
‫The layout inflator is a class in Android that is used to instantiate layout XML files into their corresponding
‫view objects.
‫Parent dot get context is used to get the context of the parent view, which is typically the recycler
‫view layout inflator dot from method creates a layout inflator instance associated with the context.
‫Then I need to call the method called inflate.
‫Inflate method is a method of the layout.
‫Inflator class used to convert an XML layout resource into a corresponding view object.
‫We need to pass three parameters.
‫The first one is the layout or dot layout dot card item layout.
‫This parameter refers to the XML layout resource that defines how a single item in the recycler view
‫should look.
‫In this case, it's the layout for displaying a sports information.
‫The second parameter is.
‫The parent.
‫This is a parameter that it is passed for the Oncreate view holder that the inflated view will be attached
‫to.
‫In this case, it's the recycler view.
‫The third parameter is false.
‫False indicates that the inflated view should not be immediately attached to the parent.
‫This is important when working with recycler view as the adapter will handle attaching views as needed.
‫And here I need to return a new view holder.
‫Ports.
‫View holder and I need to pass the item view as a parameter.