‫We created the sports Viewholder class and this class will act as a viewholder.
‫It holds the references to the views within the item layout.
‫If we go to the card item layout, we have two views the text view and the image view.
‫For that, I'll create a text view reference Alt+.
‫Enter to import the text view class and the image view image view.
‫Then I need to create a constructor.
‫Alt+.
‫Enter to create the constructor matching the super.
‫Then I need to find the view by ID for the text view and the image view for that text view equal.
‫Find the view by ID or item view dot.
‫Find view by ID or.id dot text view and I'm using this item.
‫View the image view equal to item view dot find view by ID or.id dot image view.
‫And don't miss that.
‫I need to make the reference for this image view, not this image view.
‫So for that I'll make it as image view card in order to distinguish it.
‫And that's it for the sports view holder.
‫Now let's move back to the methods on Bind the view holder and get count item.
‫Count.
‫The on bind view holder method is called for each item in the list and is responsible for binding the
‫data from the sports object to the views within the sports view holder.
‫This method sets the appropriate text for the name and the image view and always make sure that you
‫don't have this Recyclerview view Holder.
‫You need to use your custom view holder that you created before.
‫So for that I'll change it.
‫Sports View Holder And this error is caused by this data type and the type parameter that we didn't
‫define here.
‫So always when you create the view holder class, pass it as a type parameter here, sport view holder
‫and for that it will create the on bind Viewholder passing a view holder your custom view holder as
‫a parameter.
‫Always make sure these steps are done carefully because many people contact me about these errors and
‫many people, many developers have these problems.
‫Make sure when you create your view holder to pass it as a type parameter here in the custom adapter
‫extends recycler view adapter and here you pass your custom view holder in order to implement the correct
‫methods.
‫And you can see that here I have an error.
‫I need to return this method on Create view holder to return a type parameter of sports view holder.
‫So for that I can remove it.
‫Sports View Holder.
‫If you don't need to make all of these changes and all of these complicated things, just pass the type
‫parameter, then implement the methods in order to prevent these errors.
‫So I'll cut, I'll show you what I mean.
‫I remove all of these three methods, three methods, and here I need to pass the view holder as the
‫type parameter Alt+ Enter to implement the methods that take into the parameter the sports view holder.
‫Click okay.
‫And here we go.
‫The Oncreate Viewholder Returns Sports View Holder.
‫The Bind The View Holder took a sports view holder.
‫So always when you create your custom adapter, create the view Holder class then extends recycler view
‫adapter and pass your custom view holder back to the unbind view holder.
‫I'll start with Sport Sport Object, equal sports list dot get.
‫And I need to pass the position here.
‫I am returning an object of type sport from the sport list at the position position equal to position,
‫which is a parameter that it is passed for the combined view holder method.
‫Then holder which is of type view holder Sports view holder.
‫This is my custom view holder text of view dot set text and what I need to get.
‫I need to get the sport dot sport name.
‫Then the holder dot image view dot set image image resource or dot or contact the sports dot sport image.
‫So this method on bind the view holder method is called for each item in the list and is responsible
‫for.
‫Binding the data from the sport object to the views within the custom or my sports viewholder class.
‫It makes sure that the appropriate text is set for the name of the sport and the appropriate image is
‫set for the sport image.
‫The last method is called get item count.
‫This method returns the total number of items in the data list.
‫It's used by the recycler view to determine how many items to display.
‫And in this case we have the data source is a list.
‫So sport list dot size will return and tell the recycler view how many items you should display.
‫Again, guys, if you have any problem, I am here to help you.