‫Welcome back!
‫We created a custom card item layout that contains only two text views, but for creating custom items,
‫you need a custom adapter.
‫For that, I'm going to create a new package.
‫I'll name it as a view, and inside this view I'll name I create a new Kotlin class named as my Recycler
‫View Adapter.
‫Inside the primary constructor, I'll pass private val user or contacts list.
‫It's of type list of contact object and another parameter is val click listener.
‫And this click listener.
‫It's a lambda expression that will take as a parameter the contact and return or execute nothing.
‫The returning type is unit which is void.
‫And I talked about the lambda expressions in the lambda expression sections.
‫This class, my recycler view adapter will extend from Recycler view dot adapter class.
‫And here I'm going to pass my Viewholder, which is a class that I'm going to create here inside this
‫class.
‫So before passing anything I'm going to create this inner class.
‫I'll name it as my view holder class.
‫And this class will take to the parameter the binding object.
‫It's of type card item binding, which refers for the card item dot XML file, and make sure you use
‫the layout tag with it.
‫So I'm referring this binding to this card item layout and this will extend from recycler view dot view
‫holder class passing binding dot route okay it's very simple.
‫And I talked about data binding with Recycler View.
‫Many in the previous videos here I'm going to pass the data type of this adapter as a class that I created
‫here.
‫So my view holder I'll add a constructor invocation here and Alt+ enter.
‫To implement the members.
‫We have the three members on Create View holder.
‫On Bind View Holder and get item count.
‫Click okay and here we go.
‫These are the three members.
‫Let's continue with the view holder.
‫I'll start with function bind contact object and click Listener Object.
‫And here I'll start with binding dot name text view dot text equals to contact dot contact name.
‫Also binding dot email text view dot text equals to contact dot contact email.
‫I'm assigning this email and name text views to the object attributes, name and email respectively.
‫Also, I'm handling the click events using the binding list item layout.
‫But if we go back to the card item, I didn't specify any ID for this linear layout, so every item
‫here inside the the recycler view will handle the click events using this linear layout.
‫So list item layout.
‫Don't miss to add this ID to handle the click events on the items of the Recycler View dot set on click
‫listener, use the click listener and pass the contact.
‫And here I need to add the codes for these three methods.
‫And I talked about these three methods in deep deep details in the previous videos.
‫Please go back to learn about Oncreate Viewholder get item count and on bind Viewholder.
‫I'll start with val layout inflator equals to layout inflator dot from parent dot context.
‫I'm going to create another variable val binding.
‫It's of type card.
‫Item binding equals to data binding util dot inflate layout inflator.
‫The second parameter is the layout that we need to add, which is our custom card item and don't miss
‫to import are.
‫The third parameter is the parent and the fourth parameter is false.
‫Then return my.
‫View holder and pass the binding object to this instance.
‫Get item count.
‫It's very simple.
‫Just add the users list and the context list size.
‫So return contact list dot size and the unbind the view holder.
‫We need to use holder dot bind method that we created here in the view holder.
‫And I'm going to bind the contact list position the current item and the click list.
‫So here I am receiving a specific contact from the contacts list using the position index.
‫And the click listener is a callback or a listener that handles click events on items.
‫This is our adapter class.
‫And please guys, if you want to learn more about these functions, please refer to the RecyclerView
‫and the previous videos in the previous sections.