Hey there.
Well we have put together the main interface of our main screen.
And we can enter the user name select the product name in our subpoena.
Next we can choose the amount or goods and get the order amount.
And now we need to add this order to our basket.
Let's apply the concept of classes that we started in the last lecture in our application.
Let's create in our application the class order in which we will save all the properties of our order
let's select a package in which Java classes are stored and our main activity class in it right click
on the package.
Select new and Java class enter the class name here.
Call it order and click Okay.
Well basically that's it.
The class is created as you can see it will be in the same package corn dot example that draw a dot
music shop as well as main activity.
See here appeared in this package.
And now let's create the fields of this class in which we will store that data of this order.
The first field string class let's call it user name in this variable we will save the user name next
the string field Goode's name
is their next field is a variable of type int quantity.
And one more field like type
double.
Let's call it order price.
And so we created our fields and our class and now we can in main activity use this class let's do the
following.
Let's when you click on Add To Cart button we will create a new object such as an order a class order
which will contain user name product name number of goods and order amount to do this.
We need to create own clique method for our add card bottom.
Let's write in this example element the attribute on click and let's call this method also.
Add to cart we can choose any name that matches the meaning and then we create the main activity in
the main activity.
This method and or adds to the automatically redirects asked or main activity.
And here in this method we can create a new object of class order
that we write order.
We will also call the object order and create a new object of the order class New Order.
Now we can set the fields of the newly created object through this variable.
That is when they add to cart button is clicked the Add to Cart method is called and the code in this
method starts to execute first an object is created then in this object we need to put this data.
Well the first value is user name the data for which is extracted from our edit text let's create a
variable of it.
Tax class
call it user name.
Edit text
and then in on create method words bind this variable to our edit text which is in the example mockup
examine layout let's see which identifier it has I.D. name ID text.
So here we arrived from Dubai.
These are DOT I.D. dot name.
Edit text
and further in the two card method we can now refer to a variable of type of class.
Edit text and extract values from this added text.
Let's write order.
User Name field user name or the object.
Order we assign to it a value which we will extract from our edit text.
In this way use a name.
Edit text get text to stream.
And now let's check whether the field of our object or the user name is set the value that we enter
in the field.
Edit text.
We could perform the output using the system out parental length comment in our Java compilation which
we compiler which we used for our exercises.
But this doesn't work in under to do androids to the.
You need to do this different thing.
We can display the value we want to test through the LOC card which we used as you remember for debugging
in the error mode.
We could view our errors and we can enter our own records in any mode for this.
For example we can write we can out food in look at this field or the object that is we write logged.
D d means debug mode.
We will output this field to the low cut in the back mode.
For example call it print user name.
We will want to display the value of the user name.
Let's write this code here.
That is what we are doing here.
We bind the string print user name and these these value.
Order not user name.
And now in our lockup we can on this line.
As a key as in the hash mark we searched or any dictionary we can find.
This value.
Let's restart our application
and alerts and for example the name Bob and click Add to cart the next now as you can see there are
a lot of records here.
Even if we look in the back mode which displays fewer acres than in a verbose mode but nevertheless
in the verbose all the information in the back is less but still a lot of information is displayed.
And how do we find this value for these.
We wrote down this key by which we can search to do this in search we enter these key print user name
and as you can see here our key appears in the cut.
And next to it and the value of the object or the don't use a name attached to it.
And it is equal to Bob.
It was displayed two times because I clicked two times on the ATM card button.
If I click it again as you see this value appears again the time of the event is displayed here.
When this happened.
This is the name of the package.
This is our package in which the event occurred.
Well one more thing here you can enter any key that is we can name it as well as our variable user name.
Let's restart the application and check since we changed the code.
We need to restart the application.
The application has restarted
or its enter the name
Let's now enter then named Jack for example and click the Add To Cart button as you can see nothing
is displayed because the old key print user is entered in the search.
And according to the old key we have only three events displayed to see the last event.
You need to put these key here where it's copied and pasted here.
And as you can see this event appears and it contains the new value.
Jack Well everything works correctly with our user name field of order object and now we can assign
the remaining fields to the order object or the value to the remaining fields of this object in the
right order not God's name and assign a value to it.
What right can we assign to it as you remember we assign the variable goods name of the string class
in the on item selected method that is called when the product is selected in the that we assign these
variable goods name the value of the elements selected in the spinner that is.
Now here we can refer to this variable that is we can assign to field of all object to this field good
snake the value of the variable goods name of the same name.
This one which is in our class
next.
Let's assign a value to the quantity field
where do we get the value for the quantity field.
Let's see.
As you remember we created the field more precisely the variable quantity in order to increase or decrease
the value of the quantity of goods.
Each time we assign a new value on this variable when increase quantity or decrease quantity is called.
That is the field of our object.
We can assign the value of our variable of the same name which is located in the class main activity.
And one more field of our object is order price
it is equal to quantity multiplied by price
we declared the price as a double variable and in the en item selected method we are signed it to a
value that was extracted from our goods map by the product name key.
Let us get the value from our variable price here and reassign the result of the product to the field
of our newly created order price object.
And now let's in the same way.
Output to our low cut the values of all our fields our order object.
Let's carpet and paste this line everywhere.
And now of course change the keys so that it would be convenient to search you buy them here goods name
and we will output by this key next here we will write left field goal.
They key a quantity by which we will look for the value of the field.
Quantity of our object.
But you see understood or underlined with the right line and rights that the type or the second argument
is not correct because it is found by the type.
String is required.
This happens because in a low cut we can only write string.
Well for this we can do this following
we can write to double quotes and concatenate it with our value and thus get the string.
When a string with a number is conquered donated a string will be displayed and this quantity will be
in it.
And now let's write in the cut or the prize and associate it with the value of the order price field
of our object that the same thing happens here because the type double is detected but string is needed.
Therefore we can likewise hold a new concatenation with this string with empty string.
And now let's check how our code works.
Let's run our application
let's leave their name in the same Jack.
Well let's choose their drums said the quantity for example to and click Add to Cart and as you can
see since our key remains the same.
We see the last event here.
It happened about six minutes ago and the next event that happened just now it is shown on these ski
to see the value.
Good good snake.
We need to enter this key.
Let's insert it here.
And as you can see the drums key appears here.
Next we can look at or the quantity the value of this field using the quantity.
Keep as you see quantity is 2 which is correct and buy the key or the price.
We can check the value of the order price field of follow object three thousand.
As you can see everything worked correctly that is using the log bracket.
We can check whether our code is working correctly.
This is also used by debugging when searching for errors.
If the code does not work correctly we can find this by writing to look further when the verification
is carried out these entries in the low cut can be deleted.
So let's do this and delete this entries.
Well well we created a new order object in add to cart method and assign all its fields of value and
the next step we need to add when this button is clicked functionality are Iran and new activity in
which we will display our order.
We will create this with the help of a new concept that we will start a new class.
Class intent.