‫So you're happy with this grid view application?
‫This is a beautiful UI application.
‫We memorize the adapters, the custom adapters, array lists and model classes, and also we learn about
‫the grid view.
‫Now in this video, we'll add the functionality to our application.
‫So we'll add the calculations and the app will perform the calculations for the different shapes.
‫We have two way of applying the calculations.
‫The first one creating a separate activity for every shape to perform calculations.
‫For example, the for the sphere.
‫I create activity sphere and perform the calculations, getting the pie radius and perform the calculation
‫of the volume also for the cylinder and so on for all the available shapes.
‫The second way is to create one activity, but containing all fields for radius of the sphere for the
‫side of the cube, for length, width, height of the rectangular prism and the radius and height of
‫the cylinder.
‫Then we disable the edit text or the fields When the user, for example, select the sphere, we disable
‫the radius of the cylinder, the height of the cylinder, the width, height and length of the cube
‫or the prism.
‫So we enable only the specific dimensions, the specific characteristics of the specific shape or the
‫selected shape.
‫To make it simple, I'll create four activities.
‫Every shape will make its own calculations.
‫I'll go to here.
‫I'll create new empty views activity and I'll start with the sphere finish.
‫And this is a new activity because I need to direct the user to it to enter the sphere dimension and
‫we need to perform the calculation of the volume of this sphere.
‫So activity sphere, this is the layout.
‫I'll start designing the layout.
‫I'll add a background back to Drawable and here I'll assign it.
‫I'll create a title for the Sphere activity.
‫I'll create a text view.
‫I'll drag it to here in further constraints and I'll add Gravity center.
‫The volume of sphere can be calculated using the following formula.
‫V equal four over three times pi times r cubed.
‫Pi is 3.14 59.
‫It's a constant.
‫V is the volume of the sphere and R is the radius of the sphere.
‫I need to create only one edit text that get from the user.
‫The radius of this sphere.
‫So for that I'll use edit text matchparent wrap content and please enter the radius.
‫I'll drag this edit text to here and infer the constraints.
‫I'll give an ID, edit text sphere and I need to create a text view that displays the results.
‫So.
‫I'll drag and drop this result to here in further constraints and I'll add padding or margin.
‫Then I'll add this constraint to this.
‫So this is our activity sphere activity.
‫I'll initialize the widgets.
‫Also, I need to add a button to allow the user to click it and perform the calculations.
‫So I'll go to this activity and I'll create a button wrap content wrap content ID.
‫I'll drag and drop it to here and infer the constraints sphere activity.
‫Initialize it alt plus enter to import the package.
‫If you have like these errors, please make a clean project.
‫Now I'll add the functionality to this button set on Click Listener New view on Click Listener.
‫And I'll get the data from the user.
‫The data represents at the radius of the sphere.
‫So string radius equals sphere radius.
‫Edit text dot get text dot to string and I need to transform the string into an int in order to make
‫the calculations and in order to transform a string into an int, we need to store it inside an int
‫variable called r use integer dot parse n and I need to pass the radius here.
‫So the parse int is a part of integer class, which is a wrapper class for primitive int values.
‫If we keep it as a string, it will not perform any mathematical calculations.
‫We need to transform it into an integer in order to make these calculations.
‫And the volume of the sphere is four over three times pi times a radius cube.
‫So I'll create a double volume equal to four over three times pi, which is 3.14 15 nine approximately
‫times the radius r cube r times r times r, which is R cube.
‫Okay.
‫Then we need to display this volume.
‫I need to display it in this result text.
‫I'll set result equal or set text v equal to volume plus and I'll add meter cube, save the project
‫and run the application.
‫But before we run, there is no way to to navigate to this activity, to the sphere activity.
‫I need to go to the main activity and the click event For the sphere item.
‫I'll use grid view dot set on Click Listener on item, Click listener New view on Click listener and
‫on item Click method is override.
‫We talked about this listener in the previous video, so please guys refer to the adapter section to
‫the list of U.S. and memorize them well and understand them well because these are very important sections
‫to understand the adapters and custom adapters and how we deal with them.
‫Create an intent because I need to navigate to another activity.
‫So intent I equal to new intent and I need to pass this as the context of the current application.
‫And the second application that I need to go is called the Sphere dot class.
‫This I can replace it with get application context that returns the context object.
‫Then I need to use start activity method and pass the intent.
‫I run again and here we go.
‫Let me click on the sphere and you can see it's directed to the sphere activity.
‫Enter the radius.
‫I need to enter 12 for example.
‫I need to change it in the here.
‫I need to change the edit text text color to white run the activity again.
‫This is how I test my real applications.
‫12 and you can see it's in white calculate volume and v equal 5428 and this number meter cube.