‫Welcome back.
‫We created our data class and our custom layout.
‫Now we need to create our custom adapter.
‫Here I'll create a new Kotlin class and I'll name it as my custom adapter.
‫Click okay.
‫Here we go.
‫This class takes into the constructor the context.
‫It's of type, context and planets, which is a list of planet alt plus.
‫Enter to import the context.
‫And here we go.
‫We pass the context objects to use it later on with the layout inflator.
‫Don't worry, when we use the layout inflator, I'll tell you here I need to extend this custom adapter
‫from adapter.
‫But there are a lot of adapters, so if I type adapter we can see I can extend it from base adapter.
‫For example I can extend from array adapter, I can extend it from simple adapter and so on.
‫Let's learn about these types.
‫There are some commonly used adapters in Android used to fill the data in the UI components.
‫Base adapter it's the parent adapter for all other adapters.
‫This is the parent.
‫This is the route array adapter.
‫It's used whenever we have a list of single items, which is backed by an array custom array adapter.
‫It's used whenever we need to display a custom list.
‫Simple adapter it's an easy adapter to map static data to views defined in your XML file.
‫Custom simple adapter it's used whenever we need to display a customized list and needed to access the
‫child items of the list or grid.
‫I prefer using two types, either base adapter or array adapter.
‫I'll use base Adapter and don't miss to add the constructor invocation for the base adapter.
‫And here I need to implement the method so Alt+ enter to implement the members.
‫And these are the four methods that we talked about in the previous videos.
‫Click enter and here we go.
‫We need to fill these methods.
‫I'll start with the first method Getcount.
‫This method returns the number of items in the data set.
‫And what is the data set passed to my custom adapter?
‫It's of type list.
‫It's called planet, so return because this method returns int return planets dot and I need to include
‫val here and val context in order to use it in the custom adapter planets dot size.
‫It's very simple.
‫I'm returning the size of the planets list passed to this constructor.
‫The second step is the get item.
‫It returns the data item associated with the specified position in the list.
‫Return it returns any which is an object, items or the planets.
‫And here I need to pass the position.
‫The third item.
‫The third method is get item ID.
‫Returns a unique identifier for the item at the specified position.
‫This is often the item's database ID.
‫This case return position dot two long.
‫Because I need to pass long, and I'm getting this position and transforming into a long.
‫The last and the very important method we need to use is get a view.
‫This method returns a view that displays the data at the specified position in the data set.
‫The converted view parameter is a recycled view that can be reused to optimize performance, and we
‫discuss it later in the next video.