Hello my name is Martez or car.
And it's literally all we're going to continue building our pre-calculate application.
So now let's go into an android studio so here it is.
Our Let's go into this content under a limited example so here it is our layout.
And here I want to show you how to interact with from our job accords with our layout views here.
So for example we do not have to interact with the speed calculator calculator text view because this
value is constant.
And we do not have to change it.
But let's take a look at this text.
This text field we have to actually interact with this text because the value that the user enters inside
it it takes is going to be of value that you're going to work with.
So this means that in order to interact from our Java codes with this one we at this edit text we need
to provide an ID for this text so that we can connect our overcoats with our edit text here and take
a look at this text view we do not have to interact with this takes you here from our job codes because
this person takes a view is going to be a constant value and it's not actually going to be changed.
So we are not going to provide our actually an idea for this text.
That's not necessary but we must actually provide an ID for this added text so that's selective editing.
And here you can see this id attribute at the top.
So for the OED to step in here.
EDT.
Enter percent and then first an entry on your keyboard.
So this is going to be the idea of these editors.
Let's select this one.
This edits yet enter number.
So here for the idea just typing here.
EDT.
Enter number and in person entered in your keyboard.
We also need to actually interact with the spot in selected spots.
And here just for the idea to they in here between calculate
and then person on your keyboard.
So here it's going to show us this dialog it says update uses just as well.
This will update all examined references and Jawa are field references.
So this is very important because when you change an idea of a specific user interface component if
you have a file or a fight inside or a project called Or And all of these references all of these IDs
all of these references are inside that fight and that fight is going to be updated constantly.
So whenever that we actually run our application anew or I'll be DOZHD specific references and IDS is
going to be created.
So it just that this our file is going to be updated is going to be updated when we actually change
the idea of this spot.
And so yes that's true.
So just to check the box that says don't ask during this session just click on yes be accepts that select
the Spartan and the idea of this button is and calculate.
And finally we need to provide an ID for these results takes.
Again we want to change the value of the state's view.
Later we want to actually interact with this takes from October Collette's so select is text view and
for the idea of say thing here he the result and then press enter on your keyboard.
So now let's go into our main activity the java file here and here inside our main activity class we
can declare some classes here.
So first of all you can see at the top it says the package.
So here it is that my package name and project name.
So here you can see this import for this import statements.
So these classes are actually imported into our file and whenever we want to use a new class inside
our file.
These are some new classes are going to be actually imported into our file automatically.
So in order to enable that or to import feature in Android studio we need to open their preferences
at the top just click on Android studio and then click on preferences.
If you're using a Windows machine you just need to click on file and then click on preferences or settings
and then click on play.
So here just click on preferences.
And here you can see this is appearance and behavior.
So if you can actually to change the appearance and we can change the menus and toolbars.
So if you click on this system settings you can see these options here.
So now let's click on the editor of the editor and click on general here.
So if I open is generally considered this option here it says auto import.
So here it says for the exam and make sure to check the checkbox Shaugh import to pop up.
And for the job it says insert imports on paste all show imports pop up optimize imports on the fly.
Make sure to check all of these actually check boxes here at unbe U.S. imports on the fly.
Sure imports suggestions for static methods and fields.
So here when you actually checked all of these check boxes you just need to click on OK.
So now let's go back to Antrix studio here.
Now let me show you the emulator so we have d text here right.
And we want to interact with this text.
So if we need to actually declare or define and it takes inside our door file inside our main activity
class.
So inside a scope by scope I mean that the opening curly place and the closing curly brace of these
men I think the class.
So inside Ismailia of the class here I can say it it takes.
So here I am declaring this rowdy actually EDT.
Enter persons.
So this is the name of my valuable.
So just put a semicolon here because here you just want to declare my variable.
I don't want to create my variable and initialize it.
So if we have another editrix that we want to interact with this one enter number.
So again it takes EDT entered number semicolon and makes sure to actually declare these variables as
private.
So put the private key word here so that other classes do not actually accidentally access the value
of these variables because those classes do not need to access these values.
So just declare them as private.
So let's go inside these and create a method here inside the curly braces of this uncreate method.
And here I can initialize my editor access so I can see it Itay inter-personal assignment operator.
So first of all I need to cast this object to R to an object.
You're going to learn more about casting later but for now just know that we are dealing with views
and an object editor is actually a subclass of view.
So here we must cast our view object to an object so that the compiler knows that we are dealing with
an elitist object not a view object.
So he has to step in here or find view by ID because we want to connect our object with our user interface
component inside our lay out.
We need to say find view Id say the transistors just they've been here or Id thought EDT and to a person
that.
So now this object is actually connected to this.
It's interpersonal and that reference is actually stored inside this variable.
EDT enter percent.
So you can see that the name of my variable and the name of this ID is actually the same.
You don't have to do that.
You can actually change the name of this variable but I prefer that the name of the variable and the
name of the ID to be the same.
And again this is not a must.
You can change the name of your ID you can change the name of your value but these two names do not
have to be the same.
So now let's actually initialize our EDT.
Enter number variables are here to stay.
And here it is the Enter number assignment operator.
Let's cast this object to an eddy takes the object find view by ID or that Id dot EDT enter number ADT
enter number semicolon.
OK so now we initialized are in.
I should edit text objects.
So now let me show you the emulator.
So let me close this keyboard so we also have the spot in calculating the result button.
So we also need to declare of idea inside our file and we need to connect are valuable with we are actually
this one with this button up user interface component.
So inside don't of the class here I can say.
So let's just step in here.
Private and then name it the type is going to be button and the name is going to be PTEN calculate
semicolon.
So now let's go inside this uncreate let's say Pythian calculate assignment operator let's cast this
object to a button object find view by ID or that Id that PTEN calculate semicolon.
So now we actually connected our object here with this one.
It is pretty and Chalte really use an interface component and we also have this takes resolved.
So let's also declare a text inside the domain of the class.
Let's say private text view takes the result semicolon.
And now let's go inside this uncreate Smurfette that takes the result assignment operator let's cast
this object to a text view object find view by id r that ID that takes the resolved semicolon.
So here it is actually our initialization process.
And now that we actually declared and defined our objects here inside of the class.
Now we can actually go inside this and create Mefford.
And here I want to create a listener for these Chatila.
The result bottom so what is it.
Listener listener allows the spot in to listen to some type of interaction so that whenever the user
actually interacts with this button that listener is going to be notified.
And it is going to actually do something according to the logic that we put inside a body of that listener.
So let's go inside this man at uncreate Smurfit here and we can't say PTEN triangulate that sets unclick
listener.
And here inside the Frances's you are safe in here.
You put the new key word here hold the shift key down on your keyboard and then present a little key
on your keyboard.
So now the autocomplete feature of Android studio is going to is going to show you this option it says
Uncle Nicholas and her two curly braces and inside the curly braces you can see these dot dot dot.
Choose this one and then press on until you and your keyboard.
So the Android studio is going to actually put these codes automatically for you.
So what is this.
This is actually an anonymous inner class that implements the unclick class or interface and that and
because that in NMC class implements that this unclick this in an interface the Smurfette here is actually
also in the override that here it is put here.
So you're going to master interfaces later in this course.
But for now I just wanted to introduce you to the process of creating a listener for a specific user
interface component in and.
Right.
But don't worry this is just the method here.
This is an anonymous inner class an anonymous in a class doesn't have a name.
It is actually anonymous.
So for now just know that we have the method and this is going to be executed.
This uncle Meffert is going to be executed whenever the user interacts with this calculated the result.
But in an effort to use a potest is supporting this uncle Mfat here is going to be executed.
Right.
So let me show you how it is done.
So for example I can actually change the background color of this takes view whenever they use their
touches this and whenever the user interacts with this button.
So here I can say TDX the result that sets background color.
And here I can say.
So hold down the shift key on your keyboard choose the color class start.
For example I can change you to yellow.
I can't change the background color of this.
Th still is all too yellow and ever that user interacts with this button.
So let's run the AF now.
Let me show you the emulator.
So now here if I click on the Spartan Now you can see that the background color of this takes is actually
changed to yellow.
Right.
So hopefully that makes sense.
Now let me comment out this line of code so that it is not going to be executed or you can actually
delete it completely.
So here inside is Uncle asked me if I can put the actual logic to the main logic of the application.
We want to say that for example they use it and the percent and then we can say to use it we can actually
allow the user to enter the number and then we can show the result.
So for example if you want to get 50 percent 30 percent of the numbers for example 200 what is going
to value what is going to be the result we want to get the 50 percent of that number two hundred.
So the result is going to be out with it here in place of this result to take that view.
So we want to get that value we want to do some calculations here some math stuff.
Let's go inside this android studio that's going so it is unclear here.
So here first of all we need to get the value the percent value which is going to be a numeric value
right of this edit text.
So whatever value is entered inside it it is going to be actually of type editable.
We need to convert that value to our float values so that it is actually of type numeric a numeric value.
Right.
So for example disparity here that is entered here is going to be off the editable Vinita change.
We need to convert this data type of this number to a float value so that it is actually a numeric type.
And then we can do some calculations on that numeric type.
So here inside is Uncle Fred.
We need to create a variable of type float so we can say float and the name of this variable is going
to be per cent per cent numeric
value assignment operator.
So here I just need to say float.
So a class called float capital F dot parse float.
And here we can pass our string value to this method and that value is going to be converted to offload
value automatically by using this method.
So inside this prentices here I can actually get the value of this as it takes I can say EDT purs it
Itay enter percent thought get text Daut to strange so we got the text of this Enter person and we converted
that value to a string value.
And now this value is going to be converted to a float value by using this method and the result is
going to be assigned to this variable per cent in numeric value.
So let's put a semicolon at the end of the statement that it create a new line so that you can see what's
going on here.
There so now we need to divide this value that is Intel here.
For example we have this person here 30 percent.
Right.
So even if you divide 30 by 100 in order to get that decimal value and then we can actually get the
total result get the actual result.
So here we have 80 percent numeric value right now.
We need to divide this percent by 100 in order to get that this money value.
So let's create another variable off that floats and the name of this value.
But is this simn value assignment operator.
So here we have these persons numeric values right.
So I can't say a person's numeric value divided by 400 semicolon.
So now that we have the decimal value here again I can create another variable of type float.
And here I can say the name of this value is resolved.
Assignment operator.
So here now that we have this decimal value we can say this symbol value multiplied by.
So here in order to actually get the result we have this decimal value right.
So they use it as another value here.
Inside these Edhi takes these EDT number actually EDT entry or number.
So for example we want to get the first two percent of 200.
Right.
So there is all this this value is going to be multiplied by disvalue by the value that is entered here.
Inside these edits this EDT enter number.
So now we need to again say float thought parce float.
And here we need to actually refer to our EDT enter number that get text that's too strange.
So in this way we are accessing our edited her number and we write this in the text.
And finally we are converting that takes to a string value.
So we pass this value here to this parts.
So it is going to be converted to a float value and the result is going to be multiplied by this value
decimal value.
So let's put a semicolon at the number statement.
Let me create a new line here so that you can see what's going on here.
The system will value is actually multiplied by disvalue.
And here we have the result.
So finally we can say here is the result that actually the said text.
So in this way by calling the stakes we can actually send a text to this text result.
Here let me show you the emulator.
So here it is RTX the result.
So th series of data takes.
And here again because this is actually a float value.
We need to convert that value to a string value because this set takes math it actually accepts us three
valued not offloads value.
If we pass a float value to the Smurfette our application is going to crash.
So let's actually say that float that this time to save in here 2st.
So we can pass a float value to the Smurfit and it is going to be converted to a string value.
And then we can actually output that value to that screen.
So that's it.
Now we can run the app.
Let me show you the emulator.
So here it is the layout.
So let's put that person here.
So for example I want to get the 70 percent of the.
For example number 300.
Now let's click on these calculate the results button.
So here it is the result.
Two hundred and ten.
That's it.
So hopefully you have actually learned a lot in this lesson and I tried to show you everything that
you needed to know in order to actually start creating Android applications in Android applications
for the Android 8 platform.
So we're going to add lots of applications lots of tutorials about creating production ready applications
to the course.
Stay tuned.
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.
Thank you very much for being a student of discourse and I'll see you in the next story on.