Hi everyone.
So in this story we're going to go ahead and we're going to create another activity called Delete martial
arts activity.
So first of all let's go to this martial martial art class and let's modify this to stream of it.
So instead of actually retaining this value let's actually first get the martial art ID plus two chords
space plus get Martia that name plus two coats space plus get martial arts price plus two coats space
plus and finally get Marshall at color.
So let me create a new line here so that you can see what's going on here.
Exactly.
So first we want to out with this idea you get Marshall.
The Marshall name Marshall Price and Marshall add color.
So let's open the Android view here if you want to add that up in here you can just click on viewtiful
windows and then click on a project.
So here let's open this up for their Java.
And here look at this first package.
Just select this package here you can right click on this package and click on new activity.
Activity.
Actually the empty activity or you can just select this package or the top menu is going to find new
activity and select empty activity.
So here we need to specify the name of this activity which is going to be delete martial arts divied
martial art activity.
Right.
So here it's going to generate a lay out File for us automatically activity like delete Underland martial
art.
Not going to be allowed to a lot of activity it's going to be backwards compatibility.
This Richard is going to be in a belt this package is here you can see this package here.
This is it is ok is fine.
Just click on finish.
So now all martial art activity class is created for us automatically and a layout file is also created
for us automatically.
And this activity is added to the manifest file automatically so we don't have to do anything here.
We just need to create the activity here and the Android studio is going to do the rest for us.
So now that we have this delete martial art activity class we are not going to design the user interface
ourselves because we do not know we do not know that how many emotional objects exist to be that needs
to be deleted.
So if you are going to design the user interface programmatically.
OK.
We are not going to work with this at much of the activity here.
For example adding Abati and what it takes you or it radio button you are going to design the user interface
by using Jobar quotes.
So let's go to this Tillett martial arts activity class.
Let me double click on the tap here in order to make this area wider.
First of all we need to have a variable of type database handler inside this class.
So here inside this class lets actually say private database handler and the name of this variable is
database handler semi-colon.
Let's go to this uncreate Smurfette and let's initialize this value that we declared inside this class
so database handler assignment operator new database handler and then we need to pass the context which
is going to be delete much of that activity that this semicolon.
Now we need to create a method here.
Look at this method here says content view.
Right now we need to create an effort in order to actually update the user interface in order to modify
the view so the name of this effort is going to be update the user interface user interface and then
put a bit of practice you semicolon so this it here when it is called it's going to update the user
interface according to how many martial art objects that we have inside are a skill like database.
So after the end in curly brace of this on creates Smurfette I'm going to create that method here.
So just typing here private's voit the name of this method is update the user interface just put up
for practice this year and then open and close this method by using these curly braces.
So first of all we are going to get all the marginal objects that are inside of the school like database
so I can't say I released.
So just in the angle brackets specified the data type of the optics that are going to be inside these
are aliased martial arts.
The name of this rowdier it is going to be all martial art objects all martial art objects assignment
operator.
So we have a reference to the state of his handler right.
So I can't say database handler that return all emotional objects semi-colon.
That's as simple as that.
Let me create a line here.
So now this valuable holds all the martial art objects that are inside our database if any exist actually.
So now I can say we need to create a variable of type relatively or an object of type relatively.
Because we want to design the user interface programmatically so relatively out and an image of this
rally.
But it's relatively out.
Assignment operator new relatively out and we need to pass the context to this construction of this
relatively.
So the construct the context actually is the lead marshal of activity that this semicolon.
Now let's create a scroll.
So just type in here scroll view and the name is scroll assignment operator new scroll view.
So let's pass the context which is going to be delete martial art activity that this semicolon.
So here the reason that we created this scroll view here is that we don't know how many martial art
objects are actually inside their school or database.
So we want to allow the user to scroll and see all the objects inside the scroll view.
So let's actually add some more lines of code here.
Let's create a radio group.
So I want to show the user the martial art martial objects as a radio buttons so that when they use
it actually the purchase or clicks on one of those radio buttons that object is going to be deleted
completely from there so like database.
And from the view.
So radio group radio group assignment operator new radio group and me to pass the context which is did
it Marshal activity that this semi-colon.
So now let's create a fully in loop in order to iterate over each object that we have inside this Adelies
all of objects.
So I can't say for.
So let's create a variable of type martial art and then here martial art co-lead all martial art objects.
So just open and close this fall in love by using this curly braces.
So here let's create an object of type radio button so just type in here.
Radio button radio button assignment operator Neo radio button.
Right.
And now let's pass the context which is this one did Marshal activity that this semicolon.
Now it's time to set the I.D. of this radio button.
So a radio button that said I.D..
So the ID is going to be the ID of the martial art object.
So we have this martial art object here right.
So not is that this fall in love here is going to be executed for each martial art object that we have
inside is Aurelia's all martial art objects.
OK.
So for the first time that this fall is going to be executed this very well martial art is going to
hold the first object that we have inside this artist and it's going to continue executing this up until
it reaches to the final object to this that is actually inside of this.
All martial artists are released and it's going to execute that and then it's going to finish executing
this portal.
So if you want to specify the ID of this video and so notice that for each martial art object you are
creating a new radio about it here.
Right.
Look at this line of code here.
So you want to specify the radio button.
So let's actually change this name the name of the city within to current radio button.
It is more meaningful current radio button.
Now lets say current radio button that said ID that I can refer to is martial art here martial arts
that get martial art ID thats it.
Now lets specify the text of this video and so current radio button that said text and the text is actually
the text of our motion of objects so the two string Meffert that we overnighted inside their martial
art class.
So I can say martial art taught to strange.
Thats it.
And finally you are going to add this radio button to our radio group that we created here in line number
58 so you already know how to use radio groups and radio buttons in the previous sections of this course.
I talked about this concept that how we can use radio groups and radio buttons in Android.
So here I just need to say radio group that at VU radio about in.
Right.
So after the end in curly brace of this for a loop here I'm going to actually create a listener for
this radio group for the radio buttons that we have inside that radio group.
So if anybody when whenever to use that I should interact with those radio buttons.
We are going to be notified.
This class with Marshal activity class is going to be notified about that.
So I can actually refer to this radio group radio group that said on ticket change to the center now
we need to pass the context.
The context is this one delete martial art.
That me actually pass the context here.
Delete Marshlack of that activity that this.
But here because we passed this contest which is going to be the listener right that this class is going
to be the listener to the interaction of the user with the radio group.
Right.
This class is going to be notified when the user interacts with you.
So because of that this class marshal activity class must implement their own check to change listener
interface.
So let's scroll to the top here and here it is Marshal activity extends accompted activity implements
on take the change the center on chinked change.
Listener radio group that unchecked change this and that this is really important.
OK ladies if that unchecked change isn't so because now this class did most of the activity class is
implemented this interface that did Marshal of activity class must implement the method which is going
to be unchecked to change Mefford that is inside of this interface so let's scroll down here.
And before the end in calibers of this emotional activity class we are going to actually implement that
effort and take it change this and unchecked change.
Listen.
So this is the Meffert and this if it has to.
PRIME MINISTER We can see the first one is Radio Group group.
It is and the second argument is checked ID.
So let's go inside this method and let's see what we are going to do now.
So we already created an instance of type database handler so I can say database handler that deletes
data was handled that delete Mazzara object from database by ID.
So we need to pass the ID of a specific Matia object to be deleted.
And look at this method.
This method has an argument of type integer and is and it is checked ID.
OK the ID of of that specific radio about it.
So I can pass the idea here.
Check ID VOIP you can pass this ID because here inside is updates the user interface method.
Inside this for a loop.
We actually created our radio button for each monster that object that we have inside this Aurelia's
right.
This really gets all module objects from this method from the database.
So here we said that the ID of that radio button is the same ID as that martial art object that we have
inside the database.
So thats why if we passed the idea here checked ID of that button.
It is going to delete that specific object with that specific ID inside the database.
Right.
So thats why it is more it is actually a very precise method a very precise way in order to delete up
a specific motion of object from our database.
So after this line of code here I can see so not just that if this doesnt make sense for now toward
Florida you can always ask questions from me.
You can send me a message and you to me or you can just post the discussion to the course and then I
do my best to answer all of your questions and make sure to watch this section of the tutorials over
and over again in order to understand what's going on here exactly.
OK.
So now after this and what I can say create a toast message in order to let the user know that that
specific martial art object is actually deleted.
So I can't say post does it make text and first we need to pass the context so the context is that much
of that activity that this comma the text is going to be the Marshall object is deleted.
Marshall object to martial art.
Object is the word karma.
Finally if it is specified the length short that shock.
Right.
So let me create a new line here.
So that's it.
This is.
Unchecked change my fate then the user actually interacts with the radio buttons that are instead of
the radio group.
This is going to be executed.
So it's going to delete that much object from our database.
So let's go back to our Mefford updates the user interface my 5th here after this line of code that
sets the listener up for these radio call here.
I can say.
So let's create our new button inside our layout.
Delete most of that activity actually so that when that user wants to for example go back to the main
activity class.
These are the can just easily click or touch that button in order to go back to that activity.
But the Andretti were all the Android devices actually have the have the capability to allow the user
to go back to their previous activity.
OK.
But we want to actually create that button here.
I want to show you how we can create that button inside your layout and just allow the user to interact
with that button.
So let's create a button button PTEN back button PTEN back.
Right.
Assignment operator new button we need to pass the context so the context is did sort of activity that
this semi-colon.
So now when it is specified the text of this button.
So just I mean he had and back that said text.
So the text is going to be go back go back right.
And then here I can say PTEN batch that set and click listener.
So here we need to pass the context.
So the context is going to be actually the listener right.
So the listener is meant to be delit marshal that activity that this.
So because this sort of the activity class is going to be the listener of the clicks of the touches
or the interactions of the user with this button.
This class must implement the view that unclick the center interface.
So let's scroll to the top here.
And after implementing this interface let's put a comma and now I can't say view does unclick listener
so because now this class delete my social activity class is implementing this interface we need to
overwrite the uncle or my friend here.
So let's scroll down here.
And before the curly brace of the still emotional acuity class I can just step in here and click.
So override this method.
And here I can just say finish.
So by calling this if it finish this do it much like if the class is going to be finished and it's going
to be eliminated so that the user so that they actually the lay out or the activity below this activity
is going to be shown to the user.
Right.
So I notice that activities are going to be on top of each other.
OK.
When we open another activity the new activity is going to be on top of the previous activity so when
we finished the current activity that the previous activity is going to be shown to the user.
So we call finish method here.
So let's scroll to the top here.
So now that we have this in our fourth expedient patch method here I can say scroll view thought at
view radio group.
So if you are adding this radio group that actually contains all the radio buttons that we created here
inside this will loop this radio clip contains all those radio buttons.
Now you are adding this radio group to this scroll view so that the user can actually scroll between
all these radio buttons or for example we have thousands of radio buttons.
These are then scroll and see all those objects.
So now I can say after this line of code.
So now that we have this spot in here and patch let's specify the feet and the height and the position
of the spot and inside are relatively.
So remember that we have a relatively out we created here right.
And we also have a scroll view this closely holds the radio group and the relatively out holds the scroll
view right.
So first of all let's specify the width and height and the position of this button back button here.
So below this line of code that actually adds the radio group to the scroll view.
I can see relatively out relatively out but lay out palms and the name of this table is going to be
Potin problems.
OK because I want to specify it it's and the height of this button assignment operator and again just
like in here relatively out thought lay out perhaps and put a pair of practice this year.
I'm going to to specify the beat as the first argument and the second argument is the height.
So here are I actually forgot to put the new keyword here.
So make sure to put in if you were here.
So a new relatively to lay out for pullups and for the first argument I'm going to pass the value relatively
out that let's put arms towards that content.
OK.
This is the weight of the button inside on electively out karma.
And again relatively out does lay out palms.
Does that content so this is the height of.
But it's simply called.
So let create actually a new line here so that you can see what's going on here exactly.
So this is are actually at the height the button pumps right.
So let's specify the position of this spot inside our relatives.
I want this button to be at the bottom of the relativity of the at the bottom of the layout so I can
say I can refer to this button perhaps here button.
Prompts that add rule relatively out that actually align parent bottom.
So it's going to align this button to the bottom of the pattern which is going to be the relatively
out right.
We're going to put the bottom inside relatively so that it's relatively or is the parent of the button.
So if you are going to align the button to the bottom of the parent switches is this one and we're going
to also position this button I should be at the center horizontal so potent parents that are the rule
relatively out that center horizontal center part isn't.
Now let's specify the margins of this.
So I can't say but Pomerantz that set margins and here for the first value of it is specified the left
margin is going to be zero comma.
And then I mean to specify the top management again.
Zero comma the right margin zero comma.
And that Bardell Margene we are going to pass the values 70.
OK.
And that's it.
This is our bottom margin of the button here.
So now it's time to add this Spartan that we created here.
These poems two are relative they are.
So you can say relatively out that at view PTEN back comma and that we need to actually pass the pot.
We're using this version of this method the child and the output.
So we created this part perhaps here 14 polyps.
That it.
And finally we need to specify the port arms.
Actually it is clearly a part of the scroll view because we want to put our scroll inside the relativity.
And once there's scroll you to take the entire weight and the entire height of the rel. out.
So I can actually again I can say scroll view does lay out palms that lay out palms the name of this
valuable is going to be scroll viewport arms scroll view prompts assignment operator new scroll view
let's say it is a pair of prentices here thought lay out perhaps scroll view that lay out poems and
here for the video they actually create a new light years or so so that you can see what's going on
here for the video.
I can actually say scroll view that lay out poems that lay out poems that match parent comma scroll.
You thought lay out poems that match parent this is going to be for the height match parent.
So if it's at the height of this scroll view is going to be much parent.
So let's put a semicolon here at the end of our statement.
And here I can add this scroll view to the relatively out so I can say relatively out that ad view scroll
view right.
Also want to pass the parts that you created here so put a comma here and just type in here scroll Vieuxtemps
OK at this scroll view these poems that relatively out here.
And finally we are going to say that this layout that he created here inside the Smurfit is going to
be the layout that we want to have.
OK.
So I can't see so I look at it.
Scroll to the top here look.
Look at this.
Here uncreate this if it is called it's contents.
If you order to lay out that activity underline did it Underland Marshall other landmarks other than
art actually.
So this method is going to be called in order to show that they are true to use user when the uncreate
and if it is called.
Right.
But here inside is uncreate me.
I said that.
OK.
All you want this to be called and if it is called You're actually designing the user interface programmatically
we are adding the scroll view the relatively out radio groups the button.
So here at the end if you're going to call this method set content view relatively at that me actually
put it you said content view relatively.
That's it.
Now in this way we are designing the user interface programmatically.
And before we run the application here let me tell you that insight is unchecked.
Change method.
So for example when it interacts with the radio button in say the radio group of any use it for example
just clicks or touches one of those radio buttons.
The martial art object that is related to the idea of that radio button is going to be deleted from
our database.
Right.
So that means an object is going to be deleted from all alleles that we have inside is update the user
interface method that means scroll here to the top.
You can see this.
Let's look at this line of code here in line number 58.
We created a variable of the released and its name is all almost all objects and we get is almost all
motional objects from the Smurfette return all martial art objects.
So according to this release we are creating a great deal about radio buttons right.
So when a modular object is actually deleted from our database This means that we are going to have
for example we are not going to have a radio button for that emotional object.
So here when they use it for example it's one of those Monserrat objects you want to also update the
user interface.
You're inside the Smurfit so that the user interface is going to show the martial art objects of all
the radio buttons that are related to the monitor the optics that are actually inside our database not
the Monserrat objects that are deleted.
So it's necessary to call this method here inside this unchecked change if it below it is at the top
of that matrix method.
So that's it.
Now let's run an application and let's see what happens.
Let me show you the emulator.
So here you can see that our application is running on the simulator.
Let's click on.
Actually let me click on this dropdown menu and here click on delete the martial art as you can see.
Nothing happened.
Why.
Because we didn't add the code to transition to the delete marshal or activity class when the user actually
clicks on that.
Actually menu item he had distilled it to.
But in this item.
So let's go to the actually to the main activity class.
Let me open the Android view on here.
Let's go to the main activity class.
Let me double click on the stop here in order to make this area wider.
So here look at this for an option I then selected.
Right.
So we have this case a statement.
If the user for example touches the monster that item.
Now it's time to add another case statement case or that Id dot delete martial art.
Art did it martial of martial art.
COLIN So this item is for any use that actually clicks or touches.
This idea that martial art and in here can create an intent and the name of this intent is going to
be delete martial arts intent.
Assignment operator new intent and we need to pass the context which is going to be main activity that
this comma and the second argument is going to be to actually the activity that we want to transition
to.
David Marshall that activity that class semicolon.
So let me create a new line here.
So now I can just say it starts activity.
Martial marshal activity intense martial art intellectually and then here I just need to return TRUE
return TRUE semicolon.
So now let's an old application.
So as you can see here our application is running on this emulator.
Now I want you to actually take a look at this.
Actually the emulator here our application is going to crash if we want to transition to the Delete
the Marshlack activity.
And I want you to pause the video and debug the application.
If I click on it again here delete the martial art as you can see.
Now my app is going to crash if I go to address you here and if I click on Android monitor here it's
going to actually show me here why our application crash if I scroll down here we can see look at these
links here.
It says delete marshal activity Java line 32.
So it says this line of code he had this method this method calling update the user interface.
If it is the cause of this error.
And we have this linkage delit monitor that activated the Java line 50.
So here now it is inside this update the user interface Smurfette and the cause of this error is this
line of code here in line number 50.
Mistakenly I added a radio group to the radio group here.
I must add late you bought into the radio.
Actually the current radio button so radio that your radio call and radio button.
OK.
Now if I run the application again if I actually click on this dropdown menu.
Now if I click on delete a martial art..
Now here we can see these marginal objects inside the scroll view.
We have these Colebatch but in here at the bottom.
So you can see here the ID of the first object of the first actually the radio button is one box and
this is the prize.
This is the color here.
If I click on one of them you can see that it's a marshal object is deleted.
If I click on this one it is actually deleted this one and this one right.
If I click on go back now you can see this is our main activity here.
Let's go to outmuscle update and let's add another object here.
Boxing and martial art place for example 2000.
The modular color for example blue here.
If I click on at it it is going to add that to our database.
And if I click on it again it is going to add that to our database.
So let's add for example a bunch of Marshlack objects through our database.
If I click on back button here now it is our main activity.
Let's go to the little marshal art activity here so you can see now we have a scroll view of all these
martial art objects that are presented to you to the user actually as radio buttons.
Right.
If the user presses on one of these radio buttons here you can see that that specific radio button is
actually deleted.
So for example this one you can see this one is deleted or this one.
So that's it.
If I could I can go back now you can see this is our main activity so thank you very much for watching
it a story are we going to add another activity of the martial arts activity.
So thank you very much for watching.
If you have any questions about the consubstantial touch you so far please post a discussion in the
course and then I do my best to answer all of your questions.