‫Welcome back.
‫Let's continue with the custom adapters.
‫And here I need to implement the members.
‫Or you can click on this red bulb.
‫Implement the members.
‫And there are four methods to be implemented.
‫Get count get item get item ID and get a view methods.
‫Click okay.
‫And here we go.
‫I implemented the four methods and I need to change the constructor invocation and add this empty parenthesis.
‫Let's start with the first method get count.
‫This method returns the number of items in the data set.
‫And here I'm passing our data set in the constructor of my custom adapter.
‫So items dot size.
‫It's very simple and I'll use the return statement because it's returning type is an integer.
‫This is the first method.
‫Let's move to the second method get item.
‫This method returns the data item associated with a specified position in the data set.
‫Here it's returning type is any.
‫So return items.
‫I need to pass the position which is p0.
‫You can change the name of this argument to position.
‫It's better than p zero.
‫Items is the passed parameter and the data set for this custom adapter.
‫The third method is get item id.
‫This method returns a unique identifier for the item at the specified position.
‫You can change the name of this parameter to position and here return position dot to lock.
‫The fourth method is a very important method.
‫Get view.
‫This returns a view that displays the data at the specified position in the data set.
‫This method is called by the adapter view, list view or grid view.
‫In this case, it's a list of view to get a view of each item to be displayed in the UI, we have three
‫parameters p0, p1, and p2.
‫Also, you can rename them as position, convert view and p2 is parent.
‫Position is a parameter indicating the position of the item within the data set that the adapter is
‫adapting.
‫Convert view is a recycled view.
‫When a view goes off screen instead of destroying it.
‫Android provides this view to be reused for the next item that comes on screen.
‫If Convert view is null and new view needs to be inflated and the parent parameter.
‫This is a view group indicating that this view will eventually be attached to.
‫It's often used in the layout inflation process to determine the layout parameters, so the primary
‫purpose of get view method is to return a view that represents the data at the specified position.
‫Let's start creating this view that we need to return because it's returning type is a view.
‫I'll start with val Inflater equals to context dot get system service.
‫And here I need to pass a parameter context dot layout inflator service.
‫And I'll use that as layout inflator.
‫I'm creating an instance of layout inflator class in Android.
‫The layout inflator class is used to instantiate layout XML file into its corresponding view objects,
‫which can then be used in the user interface.
‫The context is a reference to the current state of the application.
‫It provides access to application specific resources and information about the application's environment.
‫The context parameter is typically passed to the adapter during its initialization context.
‫Dot get system service.
‫This part of code retrieves the system level service for layout inflator.
‫The layout inflator service is a constant that represents the name of the service and get system.
‫Service is a method of the context class that returns the and the handle to a system level service as
‫layout inflator.
‫The result of get system service is casted to layout inflator.
‫This is necessary because Get System service method returns a generic object and we explicitly cast
‫it to a specific type we want, which is layout inflator in.
‫In this case, we are obtaining an instance of layout inflator from the system service and layout inflator
‫will be used to inflate Xaml to display.
‫Inflate means display Xaml layouts into corresponding view objects.
‫This is commonly used in custom adapters to create or reuse views for items in a list view, recycler
‫view, or similar UI components.
‫So this is how we use the layout inflator in Android.