‫Welcome back.
‫Before we move to the main activity, I need to mention this very important note here.
‫The double exclamation mark in Kotlin is the non-null assertion operator.
‫It's used to assert that an expression is non-null and tells the compiler not to worry about nullability
‫for that specific expression.
‫However, it also means that if the expression on the left side is null and null, pointer exception
‫will be thrown at runtime.
‫In the Getview method, the Itemview and this double exclamation marks used to assert that the itemview
‫is not null.
‫This assertion is made based on the assumption that the Itemview should never be null at this point
‫in the code.
‫However, if for some unexpected reason Itemview is null, a null pointer exception will be thrown,
‫so the double exclamation mark.
‫The non null assertion operator is used here to tell the compiler that the Itemview should not be null
‫when returning from the Getview method.
‫Now let's move to the main activity and here I will create four shapes and store them into the list
‫and populate them into this Gridview.
‫For that, I'll start with the same steps with the same algorithm.
‫I'm teaching you how to think, how to follow my steps in order to provide any possible errors or mistakes,
‫or forgetting any code that will result in problems.
‫The first step is to initialize view, which is in this case the grid view.
‫So val grid view it's of type.
‫Grid view equals to find a view by id r.id dot grid view Alt+.
‫Enter to import the class for the grid view.
‫And the second step is to create the data source.
‫I need to copy these images.
‫And by the way you can find them in the resource folder provided under this section.
‫I'll copy these images to the drawable folder.
‫Paste them here.
‫And these are my images.
‫These are the backgrounds and these.
‫For the shapes I'll create a list of grid items.
‫But before I need to create the shapes.
‫So var shape one.
‫It's of type shape equals to shape I need to pass the image and the name.
‫So r.id dot or r dot drawable dot sphere.
‫And here sphere.
‫And I'll create the other shapes.
‫And here we go.
‫These are the shapes.
‫I'll create the list.
‫So val grid items equals to list of type shapes.
‫And I'll add them.
‫So grid items dot add I'll make it as mutable list of or I can directly add them here in the initialization
‫shape one, shape two, shape three and shape four.
‫Or you can use a mutable list of shapes and you can add them by using the add function.
‫Now I need to create the third step which is the adapter val custom adapter.
‫It's of type custom adapter.
‫My custom adapter.
‫I'm passing this as the context and the grid items, which is the list grid view dot set.
‫The adapter equals to custom adapter.
‫Here I am linking the adapter with the grid view.
‫Now I need to set item click listener if needed.
‫And of course we need to use it because I'm going to transition from the main activity to the second
‫activity, or the third or fourth or fifth, because I'm going to allow the user to select one shape
‫and go to another activity that will calculate the volume for this selected shape.
‫But at first I need to run it and ensure that our grid view is displaying the items.
‫And here I need to add a background.
‫This is the image that I created and the text view should be in white.
‫Now let's run our application and if you encountered this you can go to the restore the Gradle and change
‫it to 34 here 34 sync now and run again.
‫And here we go.
‫This is our grid view.
‫I need that to display the text, the titles and the names of the shapes in white.
‫So grid item layout go to here and change it to White Run again.
‫And this is better sphere cube prism and cylinder.
‫Now we need to handle the click events on these shapes and direct the user to the new activity that
‫will calculate the volume for the selected shape.