So now I am inside these main activity class and I want to actually implement this on method here.
Right.
First let's change the name of these arguments to view inside this method.
I tried to create a variable of type martial arts putten so that button and here I can't say much a
lot but an assignment operator.
So now I want to cast this view to a martial art but an object.
So I am 150 percent sure that I have martial art partons inside my main activity.
My main activity actually but this view here doesn't know that.
So the church has the to our martial art but then I truly object.
So I can't say I can't put a lot of private practices martial or pattern here and I can just say View
semi-hollow right in this if you are casting this view which is going to be the view the button that
is triggering the action.
So it is referring to an emotional button.
So here we are just casting it to a marshal but an object and yet assigning it we are assigned to this
value.
But martial arts button now I can for example initialize my body but that I created in this class let
me scroll to the top here you can see this variable here total martial arts place right.
Let's scroll down here let's go and say this and uncle method and here I can say total martial arts
price assignment operator total martial arts price plus added.
I can refer to this martial art button here.
That gets martial art.
Price semi-colon right.
So I think the value the current value of the total martial arts price to the value of the martial art
martial art and that is actually interactive that is clicked or touched.
Right.
So and we're assigning it to this.
Evaluate the price of that specific product that is being interactive that is being touched or clicked.
We are actually adding that value to the value of the total price.
And we are assigning the result of this operation to this valuable total martial arts price.
So now after this line of course here let's actually create a new light here.
So let's now format the martial art price here so let's create a value of type strange and the name
of this variable is going to be martial arts place martial arts price formatted assignment operator
can refer to this number for math class number format that get currency instance that format.
So when I call for format here I can pass a value of type double to the format.
MF It is and it's going to actually give us the currency instance from this life if it is going to give
us a specific Actually the format of the price of the user's locale.
So let's call it here and then I'm going to show you how it works.
So let's actually pass this total Musharraf's place here to the Smurfette semi-colon.
Let me create a new line here so that you can see what's going on here.
Let me also create a new line here.
So now that we have this model of the price format let's create a toast message so toast that makes
text first we need to pass the context main activity that this come up and that we need to actually
specify the text which is going to be martial that place.
So Marshall Price for math so Marshall Price formatted this is going to be the takes so it is actually
of type string.
So it is OK to put that here come on.
And then we need to specify the length which is going to be short data show let me create a new light
here.
And you've got to actually show this message this martial arts prize formatted here to the user.
So let's run the application now.
Let me show you the emulator so you can see that our application is running on the simulator.
And now I want to click on this martial arts button here so you can see that the price is to follow
right.
If I click on it now it says $2000.
So that's why we actually formatted our Marshall Price to that current locale.
Right.
You can see that here if I click on this one here this is Marshall put in here.
Now it is $4000.
If I click on this one now it's just $6000.
It is actually adding the value of the Marshall Price to the current value of the total Manjunath price
here.
So for example this one or this one.
So now are you going to allow the user to reset these the value of these total Marshall Price here.
OK.
So let's see how we can do that.
Let's go back to android studio and let's go to this method.
An option item selected here.
Right.
Let's create another case statement.
So case our thought Id that reset just like in here is set as you can see we don't have a reset item
here inside our menu.
We need to create that.
So in order to do that let's open our Android view here you just to click on view to the windows and
then project.
So just opened this up folder and the rest folder and here and this menu.
Double click on this menu that underlie today in here.
Let's add another item here.
Let's open attacked and just happened yet idea.
And the idea is going to be.
So in order to specify the ID first we must pass at sign Plus Id slash and then we can actually say
martial arts martial arts underline a priceless underline resets.
Right.
And then we need to specify the title.
So here I can say reset the prices.
Of martial arts or I can't say reset Matia that prices are reset.
Martial arts martial arts prices.
And finally you need to specify that sure as action if room and then itself close this tact by just
putting a slash and then at this closing track here so that cities are IDM Let's go to our Actually
the main activity class here and here I can't say Chase are thought Id that just they've been here reset
Marshall marshal prices reset.
Colin and here I can create.
Actually we don't want to create an intent here we just want to reset the prices so I can refresh to
is total martial arts price here and I can assign the value zero point zero to this variable.
And finally I just need to return true from this case return to semi-colon.
But let's run our application again.
Let me show you the emulator.
So here you can see that Apple is running on the simulator.
So first let's click on this one to each box.
Now it is $2000.
Let's click on this one.
$4000.
This one $6000 and this one now is $8000.
Now I want to reset the prices.
So here let's just click on the ellipsis button here this dropdown menu here and now we have a new IDM
reset.
Martial arts places.
If you click on it here now the prices is actually the total prices value is zero.
So let's click on this one here.
Now it says $2000 here right.
If you want to you can actually just create a Toastmasters year.
Below this item here for example for this chase or the idea that martial arts martial arts is reset
I can't say toast that make text and that I can pass the context main activity that this come up.
And then here for that message I can't say that I can't pass the value here.
Total market of prices here plus two coats come on.
And finally I can't say Len shorts that show let's run the app.
Now let me show you the emulator.
So here let's click on this one.
Each box in here this one now it is $4000.
Let's reset the prices here.
Now it is actually showing us this value at zero point zero.
It is now reset.
If I click on it here again now it is $2000.
So let's click on the dropdown menu and let's go to the Delete the marshal activity here.
Let's delete all these.
Actually most of the objects that we have inside our database.
Let's click and go back here.
Now you can see that are actually our main activity here is not updated here.
We can see that we have still these martial art buttons here which we shouldn't have this much a lot
of buttons here.
There is actually a bug inside that application.
How can we solve this problem.
So here I want you to pause the video and then actually start debugging the application.
According to the debugging skills that you have learned throughout this course first of all let me tell
you that.
Don't panic OK.
Don't panic and just think about what's going wrong here and actually try to debug the application when
you're ready.
Just play the video again.
And then here I'm going to show you what's wrong with our application.
OK.
So now let me tell you what is wrong with it.
If it's your insight modify use an interface method here you can see that we here we have this IIF statement
and here we are saying that if all martial art objects that size is actually greater than zero.
Only in that case is going to execute the codes inside this code inside the curly braces of this if
statements.
So we have this line of code here scroll view that remove all views in lay out.
So this method here is going to be executed only and only if the size of the.
All martial arts objects are Adie's is greater than zero.
Right.
So we need to think about a another way in order to solve this problem.
So here let's actually cut this kind of quick here.
And let's put it here before this if statement.
And below is actually released here.
Let's put it here now.
Let me run the application again.
Let me show you the emulator.
So this is our application and we have no martial arts objects here.
OK.
At martial arts activity here let's add a martial art here for example this time we want to teach boxing
kickboxing the martial art price is for.
For example one thousand dollars and the marshal of color is yellow.
Right.
Let's at the martial art let's for example add a bunch of martial arts you just click on the spot in
here.
So let's click on back button here.
Now we have these martial arts here right.
This monster that buttons.
So now let's click on this ellipsis button here.
Let's go to the delete marshal activity here.
Now let's delete all these martial arts objects here that just click on them in order to delete them.
Now let's go back and here you can see everything is gone and our application is working properly here.
Right.
Why.
Because I am calling the Smurfette here before this if statement not inside this statement because if
you actually for example delete all Monserrat objects then it cannot actually for example remove all
these views here that we have inside the scroll view because this statement here this condition evaluates
to false.
So it's not going to execute the codes inside this statement.
So we just put this line of code here before this statement.
Right.
Whenever this method is going to be called you're going to remove all the views that we have inside
the scroll wheel and there we can actually for example look at this condition and it's a hoot.
All these quotes here.
So let's add another object here.
So for example let's get behind this at martial art here.
For example this time I want to add Judo.
Right.
And the martial law applies for example $5000 and martial art color here is for example green.
Right.
Let's add some martial arts here to our database.
If I recall back here you can see that we have these patents here.
Now I can go to the for example did Monserrat here.
I can delete some of them if I can you can go back here.
Now you can see that it is actually the updated view is updated properly and it works fine.
So that's it.
This is our application this is the end of this app and I hope that you have learnt a lot of concepts
actually about a school.
You have mastered if you have finished this apps up until this actually does part.
You have finished actually mastering a skill light in Android.
You are now actually askew like master.
Make sure to create applications of your own and use as a light database in your own applications in
order to actually just practice on these very helpful skills very precious skills.
Thank you very much for watching.
If you have any questions please post the discussion in the course and then I'll do my best to answer
all of your questions.
So I'm going to create some more actually application some more awesome applications.
And I'm going to add them to the course.
So make sure to actually stay tuned.
I will add them to the course.
I will add some new tutorials in order to create some production the applications.
Thank you very much for watching.
And as I said earlier.