‫Welcome back.
‫We created our custom adapter and we created our custom item layout.
‫Now let's move to the main activity and use this custom adapter to populate a list view in the Oncreate
‫method.
‫I'll start instantiating the view, which is in this case a list view.
‫Val list view equals to find view by id r.id dot list view.
‫The second step is to create the data source, and in this case it's a list of planets.
‫I'll copy these images for the planets and paste them into the drawable folder.
‫By the way you can download all these assets, all these source codes from the resources folder under
‫each section.
‫This is the image of Earth, Jupiter, Mars, and so on.
‫Now I want to create a planet objects for every planet in the solar system.
‫I have eight planets, so I need to create eight variables.
‫I start with val planet, one equals to planet.
‫And here I need to pass three parameters.
‫The title, which is the name of the planet.
‫I'll start with Mercury, zero moons, and the image which is r dot drawable dot mercury.
‫In the same way I'll create the other planets.
‫And here we go.
‫This is our data source.
‫I created eight variables.
‫I need to add them to our planets array list.
‫So for that I'll create a list var planets list equals to array.
‫List of planet and planets list dot add I need to add the eight planets that I created.
‫And here we go.
‫The third step is to create the adapter.
‫VAR adapter equals to my custom adapter.
‫And here I need to pass two parameters.
‫The first one is the context and the second one is the planets list.
‫Then I need to set the the list of view adapter to this adapter list view dot adapter equals to my adapter.
‫I name it as my adapter.
‫Okay, save the project and let's run!
‫Congratulations guys!
‫We created our custom list view that displays all the moons, all the planet names, and the planet
‫image in this professional way.
‫This is a very important application we build together in order to understand and master how to create
‫a custom list view in Android.