‫Data binding util dot inflate method is provided by the Android's data binding library Android X data
‫binding for inflating a layout and creating a binding object.
‫And inside this inflate method I need to pass four parameters.
‫The first one is layout inflator dot from parent dot get context.
‫It creates an instance of layout inflator associated with the context of the parent view group.
‫The layout inflator is used to inflate XML layouts into view objects.
‫Again, if you have any doubt or you need more information about layout inflator, please refer to the
‫recycler view section.
‫Then I need to pass the layout, the custom layout that I need to display as items of the recycler view.
‫So r dot layout dot contact list item.
‫This is the resource ID of the layout XML file you want to inflate.
‫The third parameter is the parent.
‫This parameter specifies the parent view group to which the inflated layout should be attached.
‫The inflated layout becomes a child of the parent view group.
‫The last parameter is a boolean fold and this case is false.
‫This parameter indicates whether to attach the inflated layout to the parent view group immediately
‫when set it to false.
‫The inflated layout is not attached to the parent at this point.
‫This is often the case when inflating layouts for recycler view items because recycler view manages
‫the attachment when necessary.
‫Then I need to return a new contact Viewholder contact list item binding passed as parameter returning
‫a Viewholder and passing the item binding as parameter.
‫The second method is on bind Viewholder on bind Viewholder method is called by the recycler view when
‫it needs to display or update an item at a specific position in the list or grid.
‫It's called for each visible item as you scroll through the recycler view and is responsible for updating
‫the items view within the data for that position, the parameters are to one of type contact Viewholder.
‫And this parameter is the Viewholder object for the item at the specified position, it holds references
‫to the views within the items layout.
‫The second parameter is of type integer.
‫This parameter indicates the position of the item in the recycler view's data source.
‫For example, an array list or data source cursor.
‫And in this case it's an array list.
‫So inside the on bind viewholder you use the holder parameter to access the views within the items layout.
‫For example, in our case we have two text views.
‫So I specify holder dot name or email, but since I'm using data binding so I need to use this contact
‫list item binding object to get the references and need to display or update an item at a specified
‫position.
‫For that, I'll make a contact object.
‫Current contact dot get index at position here.
‫I'm getting the current contact, then I'll use holder dot contact dot set contact to current contact
‫again on bind.
‫Viewholder is used to display or update an item at a specific position in the list.
‫This method determines the total number of items in the data set that will be displayed in the recycler
‫view.
‫So this method is used to specify the total number of items that the recycler view should display.
‫And in our case, I need to get the size of the contacts list that we created and here I need to check
‫if contacts array list doesn't equal to null, then go and return contacts dot size, otherwise it will
‫return zero.
‫So this is how we create the adapter and how we link the recycler view with data bind.
‫And one last thing I need to mention and add is the notify data set changed here.
‫I need to use public void set contacts.
‫This is the setter of this array list.
‫Or you can simply add like this alt+ insert setter and this contacts array list.
‫Under this I'll use notify data set changed method notify data set.
‫Changed method is a method provided by recycler view adapter class to inform the.
‫That recycler view that the underlying data set has changed and the recycler view should refresh its
‫views to reflect these changes.
‫It tells the recycler view that the data has changed and that it should rebind the views, possibly
‫creating new views and updating existing ones.
‫You typically call notify data set changed method after making changes to the data source that the recycler
‫view is displaying.
‫So this is our adapter class that extends from recycler view and we learned about how to use data binding
‫with the recycler view.