‫Welcome back.
‫Let's continue with the sports adapter.
‫And we finished our view holder class.
‫Now let's implement the three crucial methods that are responsible for creating and managing views within
‫the recycler view Alt+.
‫Enter here.
‫I need to change the constructor invocation to add this constructor, and here Alt+ enter to implement
‫the members.
‫There are three members three methods on create Viewholder on bind Viewholder and get item count methods.
‫Click okay to implement them.
‫Let's start with the first method on create Viewholder.
‫This method is called when the recycler view needs a new Viewholder instance to represent an item.
‫It's responsible for inflating the layout for a single item and returning a new instance of the Viewholder.
‫The parent parameter is a view group into which the new view will be added.
‫The view type parameter is used when the recycler view has multiple item types, allowing the adapter
‫to use different layouts for different types of items.
‫I'll start with val v equals to layout inflator dot from parent dot context and inflate method R dot
‫layout dot card item layout.
‫The second parameter is parent and the third parameter is false.
‫Then I need to return my view holder and pass v as parameter.
‫The layout inflator is a class in Android used to instantiate layout XML file into its corresponding
‫view.
‫Objects from method is creating a layout inflator instance associated with the context of the parent
‫view.
‫Inflate.
‫Inflate is a method used to inflate a layout resource file into a view object.
‫Dukes into the parameter three parameters r dot layout dot card.
‫Item layout is the first parameter.
‫This is the resource ID of the layout file to be inflated, and this is our custom layout that we created
‫before parent is the parent view to which the inflated view will be attached.
‫It's typically the recycler view itself.
‫False indicates that the inflated view should not be attached to the parent view immediately.
‫The recycler view will handle attaching it later.
‫So in summary, this code is creating a new view called V by inflating the layout defined in the R dot
‫layout.
‫Dot card item layout.
‫This view will be used as a single item in the recycler view, and will be attached to the recycler
‫view later when needed.
‫This is a common way and common pattern when implementing Oncreate Viewholder method in the Recycler
‫View Adapter class.
‫Then let's move to the get item count.
‫This method returns the total number of items in the data set that the recycler view should display.
‫It's used by Recycler View to determine how many items there are in the data set, so it knows the range
‫of positions the request Viewholder instances for and to control the scrolling behavior, the implementation
‫should return the size of the data, set the size of a list, or the number of items retrieved from
‫a database or data set.
‫So here I need to return sports list dot size.
‫Since our data source is sports list, it's of type array list of sports model.
‫We need to use the size to get the total number of items in our data set.
‫The last method is unbind Viewholder.
‫This method is called when the recycler view wants to bind data to a specific item at a given position,
‫it receives the viewholder, the holder, and the position as parameters.
‫The method is responsible for taking the data at the specified position in the data set, and binding
‫it to the views within the view holder.
‫This is where you update the content of the views based on the data associated with the item at a given
‫position.
‫Let's bind the data.
‫So I'll use holder instance.
‫It's of type my view holder and holder dot spec.
‫Image dot set image resource.
‫I'm using this method to set the image background sports array list.
‫I'm getting the current position.
‫I'm using this position parameter of the unbind Viewholder method to get the sport image.
‫Then we need to use the same holder to get the sports name dot set text and here sports list.
‫Getting the current position dot sport name I'm getting sport name, attribute and sport image from
‫the sport model object listed inside sports list.