‫Let's continue with my custom adapter.
‫In the previous video we created my custom adapter constructor having these two parameters, the Shapes
‫array list, which is the data source and the context.
‫Then we created this Viewholder static class matching the references for the image view and the text
‫view.
‫Now, in this video we'll create the Get View method to customize what type of view is used for the
‫data object, override, get view method and inflate a view resource.
‫So for that I'll start by get a view, click enter and you can see this is our get view method.
‫I remove this return statement and I'll start with my own custom get view.
‫This method will check if a recycled view view that went off the screen is available.
‫If it is not, you inflate a new layout and create a Viewholder instance.
‫If a recycled view is available, you simply update the data in the existing view holder and reuse it.
‫So this method is responsible for creating and returning a view that represents an item within the adapters
‫data set.
‫This method is called by the framework whenever a new item needs to be displayed on the screen, such
‫as when you are scrolling through a list, view or grid view or similar list based UI component.
‫And we talked about this method in deep in the adapter section and in the list view section.
‫So please refer to them if you have any doubt.
‫Anyways, I'll break down the get view method.
‫I'll start with the first parameter.
‫The position of type N.
‫It stores the position of the item within the data set that should be displayed.
‫The second parameter is the convert view, which is of type view, a recycled view that went off screen
‫and can be reused if convert a view is null, it indicates that there is no view available for recycling.
‫You need to inflate a new one and this is what we're going to check.
‫Null or not.
‫The third parameter is the parent, which is of type view group, the parent of view group that will
‫eventually hold the returned view.
‫Let's start with the first step.
‫Get the shape object for the current position.
‫I'll create shape shape shapes equal to get item at specific position, which is the position parameter.
‫The second step is inflating the layout.
‫Here we need to check if the converted view is null or not.
‫For that I'll create my viewholder instance, my view holder and I'll create a final result view.
‫Or you can display directly or return the converted view.
‫I'll check if convert the view equal equal to null here.
‫If the convert view is null, you need to inflate a new layout for the item.
‫This is where you use layout inflator to inflate a layout XML file and else.
‫This is where the convert view it's not null.
‫It means there is a view that went off the screen and can be reused.
‫This helps improve performance by avoiding unnecessary views.
‫Inflations.
‫Let's start with the case that we need to create our new view.
‫I'll start my view holder equal to new my view holder creating this instance and layout inflator.