‫Welcome back.
‫In the previous video, we created our Viewholder class, which is a custom viewholder class, holding
‫the references to the views within the item layout.
‫Also, we implemented these three methods when extending a recycler view adapter.
‫So the Oncreate view Holder is responsible for creating new view holders for your items.
‫You inflate the item layout XML and return an instance of your custom view holder class.
‫Unbind The View Holder.
‫This method binds the data from your data set to the views within the view holder.
‫It's called when a new item is scrolled onto the screen or when the contents of an item need to be updated.
‫So I need to update the title dot set text item dot get item name.
‫In the same way, I need to update the description dot set text item dot get item description.
‫So this item is the modal class instance holder dot image view dot set image resource item dot get image
‫method.
‫So I am binding the data from your data set to the views within the Viewholder holder dot views.
‫These are the views of the viewholder.
‫Let's move to the last method which is get item count.
‫This method returns the total number of items in your data set.
‫It tells the recycler view how many items it should display.
‫And of course, in this case I am using a list so you can see item list.
‫So simply I can use items list dot size.
‫And here I'm telling the recycler view that I need to display items according to the list element.
‫Now let's move to the main activity and bind all the three parts, the data set or the modal class or
‫the list or the data source with the adapter view, which is in our case, a recycler view using the
‫bridge, which is the adapter.
‫I'll start with the adapter view Recycler View recycler view Alt+ Enter to import the class and you
‫can see the recycler view is implemented from the widget package in Android.
‫I'll initialize it here.
‫Recycler view equal find view by ID or.id dot recycler view.
‫The second step is the data source.
‫I'll create a list of item which is the modal class.
‫Alt+.
‫Enter to import the package util from Java package that contains the list class and I'll name it as
‫item list.
‫I'll initialize it here as an array list.
‫And this is the polymorphism because array list implements the list.
‫So array list is a list.
‫I need to create objects of type item and add them to the list.
‫So I'll start with item number one I1 or item number one equal to new item.
‫And in the constructor for the item I need to pass imageview and to string.
‫So here the item image r dot drawable dot.
‫I'll start with fruits, fruits and I need to add the description which is a text fresh fruits from
‫the garden and I'll create the other items.
‫And here we go.
‫These are the six items that I need to add them to the item list.
‫The third part that I need to initialize is the bridge, which is the adapter.
‫So I need to create an instance from my custom adapter.
‫And I need to pass the item list, which is the list that I added to it.
‫The six items recycler view dot set adapter to adapter and here we go.
‫Save the project and run the application.
‫And if we run, we can't see the items of the recycler view.
‫Why?
‫Because we need to add the linear layout managers that allows us to arrange and display items in a linear
‫vertically scrolling list.
‫So the solution is in the next video.