Alright, so now that we've got our activity to play a single video, we're going to extend the app to also allow a
playlist to be played.
Now this'll be a good opportunity to show how one activity can start another, something you really
need to do a lot in Android apps.
So we're going to start by creating the layouts for main activity and standalone activity, and they're both
very simple layouts, just containing two buttons each.
Now the activity_main layout was created for us by the wizard when we created this project.
So I'm going to edit that layout and delete the Hello World text view, and then drag two buttons onto the layout.
So I'm going to open activity_main. I'm going to delete the Hello World widget, the text view that was
added automatically, and then as I mentioned I'm going to drag two buttons onto the layout.
And what I might do is just close the project pane a little bit to make a bit more space for us here. That's probably large enough so
let's go ahead and do that,
and I'll drag too. Now the buttons need to be constrained,
so I'm going to create constraints for the top button to the top and left edges of the layout,
like so, and what I probably should have done was set the default margins to 16 first so I'm going to do that
now, and what I'll then manually need to do is just change those to 16.
That just gives us a bit more space.
And the second button needs to be constrained to the first one, so it's top edge is constrained to the bottom
edge of the first button, and then we also want to constrain the left edge of that button to the left edge
of the first button. Let's go ahead and do that, to
the left edge of the button as well.
Now margins of sixteen's obviously OK, we've set that, but remember that this second button, the left constraint
needs a margin of zero to line it up to the first button, because you can see it's indented there, so I'm going
to change that to zero, because of course its constrained to the left edge of the first button.
Now we need to give the buttons an ID, and also put some text on the buttons.
So I'm going to click on the, or select the first one, and we'll call this one btn. The ID will be
btnPlaySingle, PlaySingle, and if it comes up and prompts it we click on yes to rename all occurrences,
and the text, let's put some text in there as well, Play a single.
And notice when I'm typing that we're getting autocomplete trying to be helpful.
You need to be careful there to make sure that you're not actually getting something that we don't want on
there so I'm going to keep typing,
Play a single video, and you may need to press escape here to close that menu down, to choose the text.
Alright so we've got the first one done. The second one, we'll call that one btn stand alone, btnStandAlone.
OK, the text for that one is going to be Standalone
Sub Menu, enter, and even though I've typed the button captions in normal case, they've appeared all in caps.
So that's controlled by this Tt button down here in textStyle, and it's automatically selected for buttons.
I think it looks better on so I'm going to leave it,
but you can get normal case by clicking that button off if you decide. Alright
so that's the activity_main layout now completed,
so I'll go into the text tab again, and I'll format the code. I didn't need to, that was OK, back to design.
Alright so let's move on to the next activity.
Now we could use a wizard to create this activity in its layout,
but I'm going to do them separately, just to show you what the wizard's doing for us.
So to create the activities standalone layout, we just need to open the project pane, right click the layout,
select new, layout resource file, making sure constraint layout is selected under the root element, and the
name activity_standalone. Everything else is fine, so click on OK.
Now this is going to be the same as the main activity layout with two buttons,
one below the other. This time the buttons are called button play video and button play list, and they're constrained
in the same way as we did in the earlier video. So let's just go ahead and quickly do that. We'll
close down the project pane again so we've got a bit more space.
OK so Button, the first one, second one, I'll constrain the first button to the top and to the left, second button
I'm going to constrain to the top, sorry the bottom of the first button, then to the left edge of the second button.
I need to change the margin on the second button to zero so that lines up correctly.
Let's go ahead and actually change the ID.
So the ID is going to be btnPlayVideo, press enter, select yes there if you get prompted, and the text,
let's call this one Play Video.
And for the second button, we'll use the ID btnPlaylist and the actual text will be Play Playlist.
Alright, I'll just go in and see whether we need to reformat, and you can see that's neatly formatted. In the previous versions
of this course,
we found that we needed to reformat the code quite a bit. But Android Studio has got a lot better these
days with how it's creating the XML, so we don't need to do that as often. It's only fairly rare that
we need to make those changes. Alright,
so at this point we're now done. The two layouts are created, and in the next video we'll start adding the
code to make it all work. So I'll see you in the next video.