Alright, so we've now got an app that
can display information from an RSS feed,
and we've customized the display by
creating our own Custom Adapter. Now at
the moment, it only displays the same
feed. Now that's still useful because you
can quickly check the feed to see what's
changed, but it would be better if we
could choose from a list of feeds and
display any of them when we wanted to. So
to do that, we're going to create a menu
for our app. So the focus of the next few
videos is going to be how to work with
Android menus. Now before I start with
the menus, though, I want to clean up our
logcat a bit. Now we're going to be
using it to see what's going on, but at
the moment, it gets, you know, a bit
full of the data that we're downloading
and parsing. Now that we've established
that that all works, we no longer
need to keep that logging and all that
information. And by the way, that's
something that you'll do as a developer.
You'll log parts of your code and once
it's all working, you'll comment out or
remove entirely the logging, and add it
in other places. That stops the logging
getting huge, and hard to navigate. Al
right, so what I'm going to look at is
our ParseApplications class, and I'm
going to comment out the logging code
for the starting and ending tags. And if
we have a look here, we've got parse
starting, so let's comment that out on line
33, and also down here where it's
ending, let's comment that out on line
42 as well. And let's also have a look at
the for loop, and that'll be on line 60 -
where are we - 65 here. Let's actually
comment out the logging for that as well.
Actually, we'll comment out the whole loop
because it was only really there to log
things. So we'll comment those four lines
out - lines 65 through lines 68. Alright, so
let's go back to MainActivity now, and
what we want to do is have a look at our
onPostExecute method here, and we've
already commented that out by the looks.
So I'm just going to actually delete
that line. I'll just make sure that that
is commented out because we no longer need
any logging about that. And the other
thing to note here, is just to clean up.
Have a look in your imports. Now in my
case, it's already removed, but if you
haven't got Android Studio set up to do
this automatically, you want to remove
the unused
ArrayAdapter import - the one that says
android.widget.ArrayAdapter.
And again, in my case, it's been removed
because I've got Android Studio set up
to automatically remove unused imports.
Alright, going back to that code in
onPostExecute again. Alright, so
onPostExecute - onPostExecute - looking at
that again, the other thing I want to do,
I commented out these these two
lines here in the previous video,
relating to the older adapter, but I'm
going to delete them completely now,
because we've got a copy of that in the
previous video's source code. And in the
FeedAdapter class, let's remove the
logging for that as well, and we can
actually remove the TAG as well because
we're no longer going to be using that.
And the advantage of doing it that way
is once I remove that line, it makes it
quite easy for us to find any logging
because it's now highlighted in red, as
you can see. So I'm gonna go ahead and
delete that. I think it's now using TAG
from another class now, in case you're
wondering why the red error hasn't
disappeared. But we'll remove all those
logging entries, and that should be it
anyway. Okay, so that's the changes to
our FeedAdapter, and check your
imports at the top. I don't need to do
anything here because, again, I've got
mine set to automatically
reconfigure unused imports, but there
might be an android.util.log
entry you can now delete as well, in
the imports. Alright, so creating menus in
previous versions of Android Studio
before version 2.2, involved typing in
the XML, but with version 2.2, Google
included a menu designer, and that's
actually still available in Android
Studio 3. So let's actually see how it
works, so we're going to open up our
resource folder, on res folder, and open
up our menu folder - there's a menu folder.
Now there should be a menu folder, but
depending on which template you used to
create the project, you may or may not
have a folder. So if you haven't got one,
you want to actually create the new one.
So, in the case of this particular
project, I used the empty activity
template when I created it, and that
doesn't create a menu folder. But it
isn't a problem, as I mentioned - we can
actually create one. The templates just
create a few of the files you need
and, you know, really just
to get you started, but you can do
everything afterwards if you've chosen
a template that doesn't include the
feature you need. So in my case, I'm going to
just click on the res folder, right-click,
click on New, and I'm going to choose
Android resource directory. Now the
resource type, you want to set that to menu.
When we do that, notice that the
directory name changed automatically to
menu as well. Everything else is fine,
as is, so just click on OK. We've now got a
menu folder, as you can see over here.
And what we now need is a menu, so let's
right-click the menu directory itself,
click on New. We want to select New, Menu
resource file, and for this one, this is
going to be a list of the available feeds
so I want to call it feeds underscore
menu. Click on OK, and we're now in the
menu designer, once that loads up. Now,
once again, don't be afraid to experiment
with the features of this designer. Once
we've created our menu, I'm gonna be
showing you how to make it appear in an
app, so you can have a play creating
menus, and just get, you know, really a
feel for how the designer works. Now
there are a few things different in this
designer, when you're using it for menus
rather than layouts. Now the obvious one
is there's a much smaller
choice of things to drag from the
palette; just items, menus, groups and a
couple of other things.
Now another difference is that there's
no blueprint, and no button to display it.
Now menus don't have constraints, so all
the buttons to do with constraints are
also not present. Now another difference
that isn't immediately obvious, is that
you can make more use of the component
tree when creating menus, and we're
gonna be seeing that shortly. To start
with though, I'm just gonna drag three of these
menu thingies - these ones here, the menu
item thingies. I'm not sure what Google's
actually calling them, and one reason I'm
encouraging you to experiment is that I
still can't find any documentation.
Menus themselves are documented, but
all the examples still edit the XML.
But anyway, let's just drag three of
these menu items,
as you can see me do there. I'll just
drop them one below the other. Now
don't worry too much about trying to
place them anywhere in particular. Once
your mouse pointer is over the design,
it'll change from a no entry symbol
to the symbol with a plus, which you
probably saw - the green plus - and you can
just let go at that point.
And once you've got two items on the
design, you can see a difference in
behaviour. So it's possible to add the
third one, either to the bottom of the
other two or in between. And I'll just
show you again - I'll just select another
one. So you can select another one. Notice
it's appearing in orange there, and I can
move something, and go up and down - you
can see the little blue line moving,
or the green line, I should say, as to
where it's going to go. And I'll put that
back anyway, for now. Basically, the
orange highlighting's to give you the feedback
about what will happen. But at this stage,
it doesn't really matter whether you add
the third item to the end or in-between
the existing ones, but obviously, that
could matter if you're modifying an
existing menu. But in my case, you saw me
just add one after the other. So what I'm
going to do first, is from the top I'm
going to give them ID, give them both, or
all, IDs. So I'm gonna select the top one,
and we'll call this one a mnu - abbreviation
for menu - then we'll put Free. The next
one, we'll call that one a mnuPaid, and
for the third one, will go with a mnu
Songs. Well actually, I probably should have changed
the titles as well, so let's go back and
do that as well. so the title is going to
be Free apps, for mnuFree. For the
second one, we're going to go with Paid
apps, and for the third one, we're going
to go with, unsurprisingly, Songs. Okay.
And we've got a warning here, about
hard-coding strings, but we'll ignore
that for now in the component tree. And
that's really all we need to do at this
stage. We will come back and look at some
of the other things we can do in here,
but for now, I just want to switch over
to the XML version, or view I
should say - the TextView - and reformat
the code if it's needed. You can see,
there's a slight change to reformatting when I
did that. I'm going to switch back to
Design, and I'm going to close the file.
It's not necessary to switch back to
Design, but Android Studio will open the
file in the mode you last left it in, so in
my case, I want to go back into Design
made in the future. Alright, so I'm
going to stop the video here. In the next
one, we're going to work on adding the
code to make these menus work. So I'll
see you in the next video.