‫The Getview method in base adapter or array adapter, is a crucial method responsible for creating and
‫returning a view for a specific item in the data set.
‫This method is called by the adapter view, which is in this case the list view to get a view for each
‫item to be displayed in the UI.
‫This method takes three parameters position, converted view, and parent position.
‫This parameter indicates the position of the item within the data set that the adapter is adapting.
‫Convert a view is a recycled view when a view goes off the screen instead of destroying it.
‫Android provides this view to be reused for the next item that comes on screen.
‫If the converted view is null and your view needs to be inflated.
‫Parent.
‫This is the third parameter, the parent view group that this view will eventually be attached to.
‫It's often used in the layout inflation process to determine the layout parameters.
‫The primary purpose of get view method is to return a view that represents the data at the specified
‫position.
‫I'll start with val Inflater equals to context dot get system service.
‫And here I need to pass context dot layout inflator service and I will cast it as layout inflator.
‫The layout inflator class is used to instantiate layout XML files into its corresponding view objects,
‫which can then be used in the user interface.
‫And here I'm using inflator to obtain an instance of the layout inflator.
‫The context is the 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.
‫Get system service and passing this layout inflator service.
‫This is the part of code retrieving the system level service for the layout inflator, and the layout
‫inflator service is a constant that represents the name of the service.
‫Get system.
‫Service is a method of the context, the class that represents and returns 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 returns a generic object.
‫We explicitly cast it to the specific type we want, which is in this case a layout inflator.
‫In summary, this line is obtaining a layout inflator instance from the system service, and the layout
‫inflator will be used to inflate Xaml layouts into the corresponding view objects.
‫Then I need to create a val a view.
‫It's of type view because I need to return a view.
‫At the end of this get view method, I want from you to focus with me.
‫Now.
‫If convert to view, I'm referring for this parameter equals to null.
‫Then we need to inflate a new view.
‫View equals to inflator dot inflate AR, dot layout, dot item list, layout parent and false.
‫If the converted view is null and new view is inflated using the layout inflator.
‫This is the view that will be displayed for the current item.
‫The inflator.
‫This is the layout inflator instance which is responsible for inflating layouts.
‫Inflate is the method of the layout inflator used to display the current passed parameter.
‫Layout AR dot layout.
‫Dot item list layout.
‫This is the identifier for the layout resource that you want to inflate.
‫This layout refers to an example layout that we created before.
‫The second parameter is parent.
‫This is the parent view group to which the inflated view will be at.
‫It's often used in the layout inflation process to determine the layout parameters, in this case of
‫a list view.
‫Pertinent is the list view itself and false.
‫The third parameter.
‫This parameter specifies whether the inflated view should be attached to the parent during the inflation
‫process.
‫Setting it to false means that the inflated view is not automatically attached to the parent immediately.
‫Instead, you will manually attach it later.
‫So this view represents an item in the list and it's not immediately attached to the list view.
‫Else if the converted view is not null, then go and reuse the convert view.
‫View equals to convert the view and this is good.
‫The third step is to bind data to the view, regardless of whether a new view is inflated or an existing
‫one is reused.
‫The method then binds the data from the data set to the views within the item layout.
‫I'll start with val item equals.
‫To get item.
‫Here I'm going to pass position as planet.
‫Here I'm using get item method and I'm passing the position which is passed as a parameter here in the
‫get view.
‫And I'm casting it as planet because if we scroll up get item returns, any and any is referred for
‫the object.
‫Here I'm casting it to a planet object that we created.
‫In this data class.
‫We need to initialize the views val title text view equals to view which I created before find view
‫by id it's of type text view and r.id dot planet name alt plus enter to import the text view class.
‫Again, we need to continue with the moon count text view and the image view.
‫After finding the relevant views by their IDs, we need to set their text and other properties like
‫this image based on the data at the specified position.
‫We get the item as current position, so we need to get use of this item to pass the title, the moon
‫count, and the moon image properties to these views.
‫Here I'll set title text view dot text equals to item dot title moon count text view dot text equals
‫to item dot moon count also the moon image dot set image resource item dot image planet.
‫Then I need to return this view that we created here.