Hi everyone in this story all you're going to master at the school like an android by creating a production
ready Android application called martial arts club.
So let's create that here.
Let's start in your Android studio project for the application name just they've here had martial arts
club martial arts club.
And here we can specify the company domain.
The package name and project location just click next here.
Choose M.M. as the.
Actually the AP 16 Android 4.1 tiddy been for phone and tablet.
Just click on X here.
Choose basic activity.
This is very important because you want to actually use the menu feature here.
Choose basic activity and then click next so you can specify the activity name layouts name title menu
resource name.
We do not want to use fragment in this application so do not check this checkbox here.
Just click on finish.
So now as you can see here our project is created.
So let me actually switch to the Design tab.
Here you can see our design here.
This is our constraint layout and this is our Takes view at the center of this constrained layout.
So here first of all we want to specify or actually many options.
First let me actually run the application and here choose one of these devices.
Just click on OK so here you can see that our application is running on the simulator.
And here we have this hello world text view.
Here we have these floats in action button which you are not going to use in this application so we
need to delete this faluting action button and we also have this menu button here inside is actually
Abdoulaye out.
If I click on it you can see the settings here.
So let's go to a hundred studio and here inside is lay out for that just double click on the activity
underline minute example let's switch actually to Design tab and here let me zoom out a little bit so
that we can see the entire actually the entire layout here so let me close this Properties window by
just clicking on this.
I can hear height and here I can select this fluting action button and then press on until key on my
keyboard so it is deleted right.
So let's go to.
Let me actually show you the menu.
So here inside this android view inside this folder we have this menu folder right.
If I open it here you can see this menu.
Underline minute exam in this example file is added to our project because we use the basic activity
right.
So if I double click on it here you can see the spaded basic activity here.
So now let's switch to text tab here and now we can see that we have a menu and we have an item inside
this menu.
So this item is sitting right.
If I show you the emulator.
Now here you can see that if I click on this menu here you can see this option here.
The item settings so we don't we don't want to use this item here inside our absolute's actually selected
here.
This item and the person behind your keyboard.
Now let's double click on this tab here menu under the name and examine in order to make this about
you there.
So let's specify the items that we want to use inside our application.
So the first item that we want to add to this menu is going to be a martial art item.
So let's open attack here and just select item and now the first one is going to be the first actually
attributes of this item is going to be the ID of this item so that we can actually leave first to the
item from our main activity class from our job of so and do it call an ID.
And here in say the coats choose this one as signed.
Plus Id slash.
And now we can specify the id the actual ID so the ID is going to be at underline martial art at Underland
Marshall on the line art.
So this is going to be the ID right.
And here lets specify the text.
The title of this item.
So just type in here title and then select title here.
So for the title just typing here at martial art the final attribute that you want to specify for the
item is actually show as action.
So we have some options here.
If room always collapse action view never to be text.
So what does this means that mean.
Surely the issue here.
What does this mean.
So by the way if you can't see the autocomplete feature here these options in order to actually open
these auto companies are here.
You can hold down the control on your keyboard and then person space on your keyboard.
So the first one is if.
If that means that if there is enough space in sight on Apple layout it's going to show this item in
sight.
Apple layout always means that it's going to always actually show this item inside or the app or layout
but again it's going to.
It depends on the space that actually is on inside our upper left and we have this never never means
that it's not going to never actually to show despite it inside an apple layout because we have actually.
This Let me show you this ellipsis here.
We have these free dots here.
If I click on it here now it's going to show us this button in these settings item right so never means
that.
So let's choose Ephraim.
OK now let's self close this item by just putting a slash and the ending tag here right.
So this is our first item so let's add another item here.
So that's open attack item and here we need to specify first the actually the ID switch statement here
ID as science plus the slash.
So the second item is going to be delete item delete actually Marshall that sort of statement here deletes
underline martial art right and then create an inline here.
So let's specify the title so the title is going to be delete the martial art and the final attribute
is going to be the show as action again if you let yourself close this item here and then let's add
another item so item.
So the first attribute is going to be the ID and add site plus ID slash.
And it is going to be up date underline martial art.
So this is the ID and the title is going to be the update martial art.
And here we have these.
So let's actually change the title to update the martial arts.
So now for the show as action attribute to step in here if room and let yourself close this item here
by just putting slash and the closing tag.
So for now these are free items in are enough.
Let's run the application and lets see if this works or not.
So now here we can see that we have an error and the error is because of the floating action button
that we actually deleted inside our activity under the limited example.
But inside our main activity class and inside these uncreate by faith we have these we have this block
of code that is related to deflect from actually floating action button.
So lets selectees these lines of Cahir and then personally the key on your keyboard.
Let's run the app now let's choose one of these devices.
So again it says that we have an error.
So here the error is because of this method insert inside our main activity class here.
If you remember inside our menu that meant menu that means that the Excel file be deleted the action
settings item right.
So here inside our main activity class inside is an option item selected Mefford.
Here it is referring to that ID which doesn't exist anymore.
So we need to actually also delete this piece of code.
So now let's run the app again.
Let me show you the emulator and now it works perfectly.
So here you can see that there is actually enough space for this at Martial Art menu idea.
Only for this taste right.
But if you want to just see the other options you need to click on this dropdown menu here and you can
see these other options.
So you can see that we have actually a typo.
Let's go to menu that magnetic Metafile.
So let me add here let me run the app again.
So here at Marshall let's open this dropdown here.
Click on it so you can see that it's most martial art and updates the martial arts.
So these are the other items.
So now that we have these items we need to actually create some activities for these items.
For example I want to create an activity for this at Martial Art item so that the user can create a
martial art and add that martial art object to the light so that we can have that and we can actually
save that that object to Escuela and we can later retrieved that object we can.
We need to also create an activity for that deletes the martial art item and update the martial arts.
So let's go to Andrew to you first class the first activity that we want to create is going to be at
a martial arts.
So let's open our view here let's open the adult view if you want to we can just click on view at the
top tool windows and then click on Project.
So now let's open the is a Java folder the first package is this package right.
Let's open it here.
Now I want to create another activity right click on this package new all you want to create an activity
not a class.
Right.
So let's actually go to the activity here activity option and here you can see these options here right.
Let's select this one empty activity.
OK.
Empty activity.
So first it's going to ask us to specify the activity name the activity name is going to be at martial
art at martial arts activity.
So here the lay name is going to be activity on the island at Underland martial art.
Right.
So it's as if you you want this activity to be the to activity no I don't want this activity to be a
lot of activity because the main activity class is actually the lunch activity.
So I don't want this activity to be the luncher and it's ass backwards compatibility at.
Yes.
Make sure to check this checkbox so that we have backwards compatibility.
Make sure that you can specify the package name but I don't recommend to actually change its package
name because you want this activity to be in the same package that this main activity actually exists.
So let's click on finish.
So now the activity is created at martial arts activity extends of combat activity.
We have this uncreate Meffert or write it for us automatically by Android studio.
And it's a set content if you order to lay out that activity Underland martial arts so you can see that
it also created an XML file for our layout.
If I actually open this last folder here inside this last folder we have this activity Underland at
Underland martial artist example.
Right.
And inside this let's go to them manifest.
Why.
Let's actually double click on it manifests year.
You can see that it also created a new tag for our martial art activity class here in this application.
So let's go back to our martial art activity here.
Let's double click on this tab in order to make this area higher inside this uncreate Smurfette.
Let's create a toast message here.
Toast that make text to make text.
So first we need to specify the context which is going to be the main activity that does come up and
then the text is going to be.
This is martial art activity karma and then the lenth is going to be short that show.
Right.
So here you can see that I passed the wrong context.
Why.
Because the context is at martial art activity not main activity.
Here we are inside this at martial art activity.
So the context it is actually at Martial activity.
We are not inside the mind of the class.
So this is the wrong context.
So let's change it to add martial arts activity.
This is the right context at much of the activity that this so why I say Atmar activity that these this
refers to an instance of type at Martial activity when we run the application on an on an emulator.
And when we want to for example Srishti this activity an instance of this activity is going to be created.
So we need to revert to an instance of type at Marshal activity as a context here.
So now it's time to go to the main activity class here and you can see that we have this main activity
class this is our uncreate Mefford.
And here we have this uncreate options menu here the Spirit is going to be called when the menu is going
to be inflated on or actually Apple lay out.
So it says just menu inflator that inflate our menu that menu that the underline may.
So it is going to it is actually referring to our menu on it.
I mean it is a small file and it is passing this menu argument here to this inflates Mefford.
So it is going to specify this menu mean the same as the menu inside our Apple layout.
So if it is necessary if you want to have these actually menu capability this menu feature inside your
app out and we have this on options I'll let them select that method.
So this is going to be actually called Vendy user touches one of the items of insight on menu.
Right.
So we have this item as the argument which is off the menu item here.
Right on option items selected.
So let's look at these comments it says handle action by item clicks here the action bar will automatically
handle clicks on the home or up but up button.
So long as you specify a parent activity and it manifests that Semmel.
So let's delete these comments.
We don't want to actually we don't want them to be here.
Now we have only this these two lines of code here.
The first one is and the idea that get ID.
So it is getting the ID of a specific ID and insight on many.
Let me show you the emulator so you can see that we have these items here right.
So the first one at March were not he is actually an item.
So Id them that get ID and ID is going to give us the ID of this item.
And its going to assign ID to this body but because of that integer.
Now we have this idea right.
So if we can create a switch statement so lets look at this line of code here we can see that the return
type of this method is of a bully and so we must return a value of a boolean from the it.
So it is the return super that unofficial item selected item.
So it is actually returning the return value of the Smurfette and the superclass.
So the superclass of this main activity class.
So this method calling here is going to do nothing.
And that's why it is called here because it must retain the value of A.
And it is passing the item here.
So now let's after this none of what I'm going to actually just switch over to switch between the values
of the ID valuable right and I can say Chase are thought Id dot at martial arts.
Id call in.
So what does this mean.
This means that if the value of this ID value bet is actually at Martial Art ID here.
So I am saying that if the user actually clicked or touched this item at martial art then I can say.
So lets create an intent here intent and here I can say at Martial Art intent at Martial Art intent
assignment operator new intent and now of this intent actually class has a constructor that accepts
two arguments the first argument is going to be the context which is going to be main activity that
does come up.
The second argument is going to be the class that we want to transition to.
So the second class is going to be a martial art activity at martial arts activity.
That class this is really important that class semicolon.
So let me create a new line here so that you can see this entire line of code here.
Now I can see start activity and I just need to pass this outmuscled intent here.
That's it.
So after this case statement I'm going to say return true.
So what is this return to roominess this retention means that do not execute any other codes after this
case a statement if this case is true do not execute any other courts after this is Chasez statement
because this is actually the case.
True and I want to transition to another instance so it is not necessary to execute any other courts
after this case statement.
So return means actually it is a little bit like a plage statement here.
Let's run the app and let's see if anything works fine or not.
Let me show you the emulator so now the application is running on this emulator.
Here let's click on at martial arts.
Now you can see that we transitioned to this activity and you saw this TOSed message here.
So let's go to our studio and let's go to.
Actually the content underlayment and and here let's select this hello world takes you and then personality
on our keyboard.
We don't want that here.