YouSub
Untitled

en English

Untitled English subtitles

0 downloads · 91 lines · added Dec 12, 2015

Report a problem
What's wrong?
Advertisement

English transcript

So, far we've built a quantity picker.
>> Right. And
the next place to go in the app is the price.
>> Yes.
The price is right.
So, price is an integer so far, but we want to move beyond that and
use strings.
>> You mean, this type of string?
>> No I mean like this type of string.
>> Huh.
>> So a string is just a sequence of characters.
>> So wait. How does this work with the price then?
>> So we're going to change the screen so that it says total.
And then $15.
So it's not just a number, now it has some text with it as well.
>> Numbers and text.
>> Yeah. Isn't that awesome?
This is from the party that you may or may not have [LAUGH] been invited to.
Over the next few videos we'll talk about using strings
in our Just Java app.
Specifically, we'll learn how to create and update string variables in the app.
Then we'll change the app so that under the price header it says total, $15 or
whatever the price is based on the quantity ordered.
We'll also show the text,
Thank you, because we're excited about having any customers at all.
You might be wondering why don't we just put all of this text
inside the XML layout?
Well, we could, but the problem is that the quantity can change and
when we hit the order button, we want the price to be updated here.
So this text needs to accurately reflect the price based on the quantity.
By using a string variable, we can change the value of the text while
the app is running without having to hard code it into the whole XML layout.
Here's an example from real apps that you may recognize.
When you receive an incoming call you see the person's name at the top
of the screen.
We can't put this name directly into the XML layout
because it will change depending on who calls you, unless all your family and
friends are called Britta Holt.
The best thing to do is to store this name in a string variable.
That way you can update it depending on who calls you.
Then when we show this screen we can just display the latest name
that is stored in that variable.
In the News and Weather app, we see a list of the top news stories.
When we build the XML layout, we can't just specifically hard code
these specific news stories into the XML layout.
As much as I love reading about the Winter Olympics,
I do want to see other news articles as well.
So we can store the information for each news story,
like the article title, as a string variable, because that can change.
For the next task I'm going to provide you with some code and
I'm going to have you make those changes in your app.
Then you'll run the app and then observe what happens.
I'll ask you some questions to see if you can try to figure out
what's going on.
The first change is to modify the submitOrder method.
You can remove the code that's already in between the opening and
closing braces and then replace it with these two lines of code.
Adding this code will give you an error, so I want you to also
add the displayMessage method, which we've provided in the instructor notes.
In the instructor notes, you'll find this Gist of code.
Go ahead and select the whole thing,
from the comment all the way to the last closing brace.
You can treat this method like a black box,
you don't have to worry about what's going on Inside of the method, you just
need to know that you want to add it to the MainActivity so that you can use it.
Back in Android Studio,
in the MainActivity.java file, I'm going to paste in this new method.
I can paste it anywhere in the MainActivity, but
I'm just going to put it right after the displayPrice method.
And I'm going to put it after
the closing brace of the displayPrice method.
Notice that it's also inside of the closing brace of the MainActivity.
The MainActivity has an opening brace right here,
and everything inside of it is contained within the MainActivity.
And then you have a closing brace for the MainActivity here.
Once we've added the displayMessage method in,
we can now modify the submitOrder method.
I'm going to erase the code that we already have inside
the submitOrder method.
Then according to the quiz image, I'm going to add the new code here.
Intentionally I'm not giving you too many details on what I just did.
I want you to try it out in your version of the app, run it, and
see what happens.
After that I want you to answer these questions.
What happens when you click on the order button in the app now?
If you take a look at the submit order code more closely,
we actually created a string variable.
Even though we haven't gone over the code for string variables, I want you to
make your best guess as to, what do you think the variable name is?
And what do you think the variable value is?
When you are done go ahead and continue.

Need subtitles from another video?