Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Preview
Start a free Courses trial
to watch this video
In this video I create the project, update main_activity.xml to only contain a ListView, and create a layout resource to be the basis of the rows in our ListView.
For the rest of these videos, I will be
showing how I chose to solve the problem.
0:00
There are lots of ways to write an app.
0:05
And as long as the app works,
you shouldn't be too concerned with how
0:07
you got it to work,
at least while you're still learning.
0:10
That said, I'm going to jump right in and
get started.
0:14
I am going to call
the app Golf Score Card,
0:18
and hit next, next,
empty activity, next and finish.
0:25
Knowing that this activity is mostly
just a big list, I am going to start
0:31
by extending list activity, remember when
0:36
we're extending list activity, our main
layout is a list view with a special ID.
0:42
Let's go ahead, and make some changes
to activity main to make that the case.
0:48
I'm going to get rid of the text view.
0:55
And drag in a list view.
1:00
Then, I'm going to give
it the ID of @android.
1:11
ID forward slash list.
1:15
Looks good.
1:20
Now, that I've got my activity main.xml
all sorted out, I'm going to create a list
1:21
item.xml, which will be the xml file
describing each row of the list view.
1:27
The first thing I'm gonna do is
change the orientation to horizontal.
1:41
And let's go ahead, and import the tools
name space as well by typing tools, and
1:48
hitting tab.
1:52
Alright.
1:53
From the mock ups,
I know that the left most column
1:58
is going to be a text view
representing the label of the hole.
2:02
Which in this case is hole one,
hole two, hole three and so on.
2:05
Next to that is another text view
that represents the score for
2:10
that particular hole.
2:13
Next to that is a button that
will remove a stroke, and
2:17
then, another button
that will add a stroke.
2:22
I'm going to use the lay out width and
lay out wait components to make
2:26
each of these fit on the screen
just a little better.
2:31
I am going to set the layout
width to zero dp as that
2:37
allows us to use
the layout_width attribute.
2:42
Layout_weight attribute.
2:54
And I'm going to set the weight of the
first TextView, which is the label, to 3.
2:57
The weight of the second TextView,
which is the score, or
3:06
strokes taken, to 2, and
the weight of the buttons to 1.
3:10
And then, let's see how that looks.
3:14
That looks pretty good, but
there's a lot of text on that button,
3:21
a lot more than we need.
3:24
Probably, pretty safe just
using a plus and a minus sign.
3:27
And while we're in the text side
of things, let's go ahead and
3:36
update these IDs.
3:39
The first ID should be set to hole label.
3:41
And I'm gonna call
the second one stroke count.
3:45
This first button,
I'm going to call remove stroke button.
3:54
On the second button,
I'm going to call addStrokeButton.
4:01
Alright.
4:05
Now, the layout dimensions look okay,
but the text is a little small, so
4:08
I'm gonna change that.
4:13
And it's going to recommend
that I use SP instead of DP.
4:23
So, we'll do that.
4:27
And I'm just gonna copy this, and
make everything have the same text size.
4:30
Alright.
4:41
One last step that i'm gonna do is change
these text to something more meaningful.
4:42
We'll change this one to be whole one.
4:48
And this one to be zero.
4:54
And then, i'm going to change
the name spaces for these two tools.
4:59
I don't want these to
actually show up in the app.
5:03
I'm just setting them to this, so
I can look them in the design tab.
5:07
And that's what the tools
name space is for.
5:10
Alright we've created both of our layouts.
5:16
You need to sign up for Treehouse in order to download course files.
Sign up