‫Since I'm going to use this layout, the contact list item, that XML file to display the items of the
‫database into a recycler view.
‫With this customized layout, I need to use a custom adapter that extends from recycler view and contains
‫a view holder.
‫So for that I'll create a new Java class.
‫I'll name it as my adapter.
‫And this my adapter class will act as a custom adapter for our recycler view.
‫I'll extend recycler view dot adapter and you can see I need to pass the H viewholder class and the
‫main purpose of a view holder is to hold references to views that are part of the individual items layout
‫within a recycler view.
‫These views can be complex, containing multiple widgets like text, view, image, view and more.
‫In our case, we have only two text views we need to display.
‫A recycler view can potentially display a large number of items and creating a new view for each item
‫can be resource intensive and slow The Viewholder pattern.
‫The addresses this issue by recycling and reusing views for different items.
‫As they scroll on and off the screen, please refer to the recycler view section.
‫If you have any doubt here, I need to pass the view holder and always when you create a custom adapter,
‫start by creating the view Holder class.
‫I'll start by class View Holder extends from recycler view dot view holder.
‫I need to extend from the recycler view dot Viewholder.
‫I need to hold the references here so private text, view, name and email.
‫But wait, why we're going to make like this and we're going to use and we use the data binding in our
‫layout.
‫So in this video I want from you to focus with me because this is a very new and very important concept
‫in Android data binding library.
‫I'm going to use the data binding with recycler view.
‫I don't need to write like this.
‫I'm going to create a reference for my item binding.
‫As I told you in the data binding library lessons, I'll start to to make the reference for this layout.
‫I need to start with the name of the layout with capital letter and the camel case and I'll add the
‫postfix or the keyword binding.
‫So contact list item contact list item and I'll use the binding keyword.
‫This is the first step and we know it.
‫Okay.
‫Alt+ enter to import this class, then I'll name it as contact list item bind.
‫I need to create a constructor and I don't need this view.
‫I need to pass it as contact list item binding dot get route and this method get route is a method used
‫to obtain the route view of the layout associated with a data binding instance.
‫It returns the route view of the layout associated with that binding object and in other words, it
‫provides access to the top level view in your layout XML file.
‫So it's a convenient way to access and interact with the route view of data bound layout in Android
‫allowing you to perform operations on the UI defined in your layout files.
‫Then back to up here I'll start adding the methods and the variables here.
‫So private array list of contacts object and name it as contacts, array list or contacts.
‫Alt+ enter import the class.
‫The second step is to pass this Viewholder here so I refer to my adapter dot contact Viewholder class
‫and I need to implement the methods Alt+ enter implement the methods we have to implement on create
‫Viewholder on bind Viewholder and get item count.
‫If you have any doubt about these methods, please refer to the Recyclerview section in our course.
‫But don't worry, I'll make an overview for each method.
‫I need to create an array list of type contacts and I need to create a constructor having this array
‫list.
‫Then I'll move to these methods.
‫I'll start with the Oncreate Viewholder on create Viewholder method is called by the recycler view when
‫it needs to create a new Viewholder to represent an.
‫Item in the list or the grid.
‫It's typically called when there is no recycled view holders available for reuse.
‫Example During the initial creation of items or when scrolling brings new items into view, this method
‫takes two parameters one of type view group and one of type integer.
‫This parent is a viewgroup representing the parent view that the view holders layout will be attached
‫to and the view type is of type an integer that represents the type of a view to be created.
‫This is useful when you have multiple view types in recycler view and you need to distinguish between
‫them and inside the Oncreate view holder method.
‫You need to inflate the layout for the items views and create a new instance of your custom view holder
‫class.
‫For that, I'll use a layout inflator, so I'll start with the content list item binding.
‫I'll create a new instance from it equal to data binding util dot inflate.
‫I want from you to focus with me because we didn't use the data binding class with the recycler view
‫in the data binding lesson.
‫So in this example, in this layout and in this app, I'm going to use the data binding with a recycler
‫view.
‫Please pay attention.