YouSub
Untitled

en English

Untitled English subtitles

0 downloads · 115 lines · added Dec 6, 2015

Report a problem
What's wrong?
Advertisement

English transcript

All right, that's enough talk.
Are you ready to look at your very first Java file?
Well, you actually have already done some work to create that file.
Let's go back in time.
Do you remember this project wizard that you used to create your new project?
Well, we selected the blank activity template,
which automatically created a new activity for us.
Then it prompted us to name that activity, and
we just accepted the default name of MainActivity.
Now, an activity represents a single focused thing that the user can do.
Sometimes, an activity is one screen in an app.
Other times, a single activity can have multiple screens.
Essentially, an activity is how you can display your layout, and
interact with the user.
In this case, we also accepted the default name for
the layout, which is activity_main, which is an XML file.
So this Main Activity is displaying this layout file.
In the Gmail app, for example, we have a conversation list activity.
This activity displays a list of conversations.
If you click on this hamburger icon, it opens up the navigation drawer, and
you can switch to other views, like the social emails, promotion emails, or
updates.
Even though these go to different screens,
they're all part of the conversation list activity.
They all revolve around viewing emails.
Gmail also has another activity called Compose activity.
This activity is for the user to create a new email.
So you can see how each activity is focused on a certain thing that
the user can do.
Here's another example.
This is the Sunshine Weather app.
This is actually the project that you can build up
in the Android Fundamentals Udacity course.
The main activity is the main screen,
which shows the list of weather forecasts for the whole week.
The detail activity shows the details for the weather forecast for
a single day.
And then the settings activity is where you can go to change location or
temperature units.
So you can see how each activity is focused on a certain thing that
the user can do.
In our coffee ordering app, we're just going to have the main activity.
Speaking of our app, the main activity for
our app is defined in a file called MainActivity.java.
Notice that the file extension or the suffix here ends in .java.
That's how the computer will know that it's a Java file.
By the way, on your computer it will look something like this.
This is simply a new file extension that you probably haven't seen before.
Other file extensions you may be familiar with are .xml,
for the activity_main.xml file, or .png or .jpeg for image files.
You can find this file on your computer by navigating through the files in your
app in Android Studio.
A lot of these files were automatically generated for us.
So, look in the app folder under java, and then com.example.android.justjava.
JustJava's the name of our app.
There are also other files if you expand out the gray arrows but
we don't need to worry about them now.
Okay, and then we can find MainActivity.
Just double click on that to open it.
I'm going to slide this view over so that I can see MainActivity better.
Now, here's all the code that Android Studio automatically generated for
us for the main activity.
Seeing Java code for the very first time can be scary and overwhelming, so
don't worry.
It's totally normal to not understand any of this.
I felt confused when I first started off, and
I still get confused when I look at files that I have never seen before.
When you see this, you may just see a bunch of random symbols everywhere,
with blank spaces in weird places.
Some words might be recognizable in English,
while others just don't mean anything to you.
Don't worry, though, we're going to understand all this code soon.
What we will do now is modify the code that Android Studio gave us, so
that our app does something when the order button is clicked.
The new code for
MainActivity is included in a link below in the instructor notes.
We want you to copy over all of this code here, and
then in Android Studio, go ahead and
select all of this and delete it, then paste the new version that we gave you.
In the code that you just copied notice how we included some comments as well.
A comment follows the following format.
It starts with these symbols, and it ends with this, and it can go on for
as many lines as you want.
The purpose of a comment is to describe the code in some way, and you can
describe it using plain English or any language that you want to use, and
it doesn't have to follow the format or the rules of the programming language.
So we have a comment up here to describe the purpose of the main activity, and we
have comments on these methods here to explain what the individual methods do.
If you want more information on writing comments in Java,
just Google search that.
It's aimed to help the person who's reading the code, either you or
other people, better understand the intent behind why that code was written.
It's also a really good habit to always comment your code, so
that when you go back to it, it's easier to read.
If you want to learn more, feel free to click on any of these links.
So feel free to read the comments that we left here.
Now, in order to make the order button do something in our app,
we also need to make one more change to the activity_main layout file.
We need to add an extra attribute to the button XML element.
The attribute name is "onClick" and the value
will be "submitOrder." Use this exact name so your code matches ours.
Also, remember the O because this method name is in camel case with no spaces.
Don't worry about what this means for
now, we'll learn more about it in the next video.
Also, if you haven't already done it, make sure that this TextView
here has an ID Of quantity_text_view.
These changes will make your layout work with the new
MainActivity Java code that we gave you.
Go ahead and make these changes now.
Modify the activity_main layout file, and
then replace the entire MainActivity Java file with the one that we give you,
and then also run the app on the device to make sure that it still works.
After all of this, if there are no errors,
then can you tell me what happens when you click on the button?
Write your answer here in this text box.

Need subtitles from another video?