‫Hello my friends, and welcome back.
‫In this video we're going to handle the click events on the grid view items.
‫By the way congratulations for creating this amazing Grid View app.
‫To handle the click event, I need to use Grid View that set on item click listener and I will use that
‫of Lambda Expression.
‫The set on item Click listener method in Android is used to set a click listener for items in a grid
‫view.
‫It allows you to define a callback that will be invoked when an item in the grid view is clicked.
‫Let's break down the parameters and the purpose of each.
‫Here, the adapter view can be replaced with an underscore.
‫The underscore is a convention in Kotlin and some other programming languages, to indicate that the
‫parameter is not going to be used in the lambda expression.
‫In this context, it's used to ignore the first and fourth parameters here.
‫Also, I can neglect it, and also the view and the first parameter represent the adapter view and the
‫id of the clicked item, which is the fourth parameter.
‫I only need to use the third parameter, which is I.
‫Also I can replace it with the position and here I need to get the clicked item from the grid items,
‫specifying the index as the position.
‫The position parameter represents the position of the clicked item in the grid view.
‫It indicates the index of the item in the data set associated with the grid view.
‫You can use this information to retrieve the corresponding data item from your data source, for example,
‫a list or an array, and in this case it's a list.
‫Now we need to use val click item equals to custom adapter dot get item.
‫And here I need to pass position.
‫Then I need in this example to pass.
‫When the user clicks on any shape to pass to a correct activity.
‫So I will create a new activity here.
‫I will select Empty Views activity and I'll name it as Sphere Activity.
‫This activity will handle the calculations for the volume of the sphere.
‫I need to direct the user to this activity.
‫So if clicked item dot dot shape name equals equals to sphere.
‫And make sure that you specify it exactly as that of the list.
‫So scroll up copy this.
‫And here I'm checking for the clicked item if it is equal to the sphere.
‫And here I need to use this question mark.
‫Then I need to direct the user to the shapes activity.
‫I will create an intent I equals to new intent of this.
‫And I will pass the second parameter which is the sphere activity class dot Java.
‫Then I need to start activity.
‫I run the program and click on other shapes.
‫Nothing happened.
‫Click on sphere.
‫You are directed to another activity.
‫So congratulations!
‫We succeeded in handling the click events on Gridview items.
‫In the next video, we're going to have to handle the functionality and the calculations of the sphere
‫volume in this sphere activity.