‫The fourth step is to create the adapter class.
‫We need a class to hold all methods dealing with the recyclerview implementation from creating, binding
‫and determining the count of items.
‫So for that, we'll create the adapter class.
‫Go to the project and here the package.
‫I'll create a new Java class and I'll name it as my adapter.
‫This class will extend Recyclerview dot adapter and I need to pass the viewholder here.
‫So when you create a custom Recyclerview adapter, you need to extend the Recyclerview adapter class.
‫This is a fundamental part of using Recyclerview widget to display lists or grids of items, and extending
‫class means creating a new class that inherits the properties and behaviors of the parent class.
‫In this case, by extending Recyclerview dot adapter, you're creating a new class that will customize
‫the behavior of base Recyclerview dot adapter class to suit your specific needs.
‫And when you extend this Recyclerview dot adapter, you're essentially creating a blueprint for how
‫the Recyclerview should populate and manage its items.
‫You override certain methods of the base adapter class to define how that data is bound to the views,
‫how many items there are and how the views are created and recycled.
‫I advise you before you continue with the adapter, you need to create the static class custom Viewholder
‫or the viewholder that extends Recyclerview dot Viewholder class and then move again to the adapter
‫and continue your code.
‫So I'll create the public static class my Viewholder in the next video I'll talk about and edit this
‫Viewholder class.
‫But now I'm creating it just to pass it as a type parameter for the recycler adapter and in order to
‫prevent any possible errors and to prevent edits for the code extends recycler view dot not adapter.
‫I need to extend viewholder create constructor matching super.
‫And here we go.
‫This is our Viewholder class.
‫I return to this class later on in the next video and let's continue with the My adapter class.
‫I need to pass the name of the Viewholder here inside these signs so I'll copy and paste my viewholder
‫class, my adapter dot, my viewholder class.
‫I'm referring to this class that we create.
‫I'll create a private list of items.
‫I'll name it as item list Alt+.
‫Enter to import the package of the list util, dot list and Alt+.
‫Enter to implement the methods on create Viewholder.
‫Unbind the Viewholder and get item count.
‫These are the most important methods that you need to override when extending Recyclerview dot adapter
‫hit Enter.
‫And these are the methods.
‫Let's start with these methods.
‫But before I miss, I need to create the constructor having one item which is the item list.
‫So we need to pass the list of items model class to display them into the recyclerview.
‫We have these three methods on create Viewholder on bind Viewholder and get item count on create Viewholder.
‫This method is responsible for creating new view holders for your items.
‫You inflate the item layout XML and return an instance of your custom Viewholder class.
‫So for that I'll create a view object item view equal layout inflator dot from.
‫So did you remember the layout inflator if you passed through the previous sections?
‫Otherwise I'll create an overview for the layout.
‫Inflator The layout inflator class is used to inflate or create a view hierarchy from an XML layout
‫resource.
‫It's an essential part of building UI components in Android, allowing you to convert XML layout definitions
‫into actual view objects that can be displayed on screen.
‫You obtain an instance of layout inflator by calling its static method from and passing the parent context.
‫And the context is needed because it provides information about the app's environment and resources.
‫Parent dot Get context.
‫So I'm using this parent.
‫Then I need to use the inflate method using the obtained layout.
‫Inflator instance you call the inflate method to create a new view object from the specified layout
‫resource.
‫In this case, the layout resource is r dot layout dot item layout that we created before, which represents
‫the individual item layout.
‫And the parent parameter is the parent view group that will eventually contain the inflated view.
‫The third parameter false indicates that the inflated view should not be immediately attached to the
‫parent.
‫It will be attached later by the recycler view layout inflator.
‫We use the from to get the context and we inflate the r dot layout item layout.
‫Then we need to return our custom view holder.
‫So after inflating the item layout, you create a new custom view holder.
‫And this is a customized class that we created.
‫So after inflating the item layout, you create in you, my view holder instance and pass the inflated
‫view as parameter this custom view holder.
‫My view holder will hold the references to the views within the inflated item layout and is used to
‫efficiently access and manipulate these views when binding data.
‫And I need to insert this keyword new.
‫This is on creative view holder method.
‫So this method on create view holder will be called by the recycler view when it needs to create a new
‫item View holder for a list item that will be displayed on the screen.