1
00:00:04,630 --> 00:00:06,880
Alright, so we've now got an app that

2
00:00:06,880 --> 00:00:09,070
can display information from an RSS feed,

3
00:00:09,070 --> 00:00:11,650
and we've customized the display by

4
00:00:11,650 --> 00:00:14,530
creating our own Custom Adapter. Now at

5
00:00:14,530 --> 00:00:16,630
the moment, it only displays the same

6
00:00:16,630 --> 00:00:19,240
feed. Now that's still useful because you

7
00:00:19,240 --> 00:00:21,220
can quickly check the feed to see what's

8
00:00:21,220 --> 00:00:23,470
changed, but it would be better if we

9
00:00:23,470 --> 00:00:24,790
could choose from a list of feeds and

10
00:00:24,790 --> 00:00:27,759
display any of them when we wanted to. So

11
00:00:27,759 --> 00:00:29,349
to do that, we're going to create a menu

12
00:00:29,349 --> 00:00:32,020
for our app. So the focus of the next few

13
00:00:32,020 --> 00:00:34,059
videos is going to be how to work with

14
00:00:34,059 --> 00:00:36,670
Android menus. Now before I start with

15
00:00:36,670 --> 00:00:38,590
the menus, though, I want to clean up our

16
00:00:38,590 --> 00:00:40,330
logcat a bit. Now we're going to be

17
00:00:40,330 --> 00:00:42,100
using it to see what's going on, but at

18
00:00:42,100 --> 00:00:43,360
the moment, it gets, you know, a bit

19
00:00:43,360 --> 00:00:44,710
full of the data that we're downloading

20
00:00:44,710 --> 00:00:47,320
and parsing. Now that we've established

21
00:00:47,320 --> 00:00:48,820
that that all works, we no longer 

22
00:00:48,820 --> 00:00:50,590
need to keep that logging and all that

23
00:00:50,590 --> 00:00:52,840
information. And by the way, that's

24
00:00:52,840 --> 00:00:54,670
something that you'll do as a developer.

25
00:00:54,670 --> 00:00:56,740
You'll log parts of your code and once

26
00:00:56,740 --> 00:00:58,900
it's all working, you'll comment out or

27
00:00:58,900 --> 00:01:00,970
remove entirely the logging, and add it

28
00:01:00,970 --> 00:01:03,220
in other places. That stops the logging

29
00:01:03,220 --> 00:01:05,680
getting huge, and hard to navigate. Al

30
00:01:05,680 --> 00:01:06,820
right, so what I'm going to look at is

31
00:01:06,820 --> 00:01:10,210
our ParseApplications class, and I'm

32
00:01:10,210 --> 00:01:11,530
going to comment out the logging code

33
00:01:11,530 --> 00:01:14,289
for the starting and ending tags. And if

34
00:01:14,289 --> 00:01:15,670
we have a look here, we've got parse

35
00:01:15,670 --> 00:01:18,429
starting, so let's comment that out on line

36
00:01:18,429 --> 00:01:21,969
33, and also down here where it's

37
00:01:21,969 --> 00:01:23,859
ending, let's comment that out on line

38
00:01:23,859 --> 00:01:27,189
42 as well. And let's also have a look at

39
00:01:27,189 --> 00:01:30,670
the for loop, and that'll be on line 60 -

40
00:01:30,670 --> 00:01:35,079
where are we - 65 here. Let's actually

41
00:01:35,079 --> 00:01:37,810
comment out the logging for that as well.

42
00:01:37,810 --> 00:01:39,100
Actually, we'll comment out the whole loop

43
00:01:39,100 --> 00:01:40,420
because it was only really there to log

44
00:01:40,420 --> 00:01:42,969
things. So we'll comment those four lines

45
00:01:42,969 --> 00:01:46,600
out - lines 65 through lines 68. Alright, so

46
00:01:46,600 --> 00:01:50,170
let's go back to MainActivity now, and

47
00:01:50,170 --> 00:01:52,450
what we want to do is have a look at our

48
00:01:52,450 --> 00:01:55,450
onPostExecute method here, and we've

49
00:01:55,450 --> 00:01:56,850
already commented that out by the looks.

50
00:01:56,850 --> 00:01:58,659
So I'm just going to actually delete

51
00:01:58,659 --> 00:02:01,090
that line. I'll just make sure that that

52
00:02:01,090 --> 00:02:02,469
is commented out because we no longer need

53
00:02:02,469 --> 00:02:05,469
any logging about that. And the other

54
00:02:05,469 --> 00:02:07,479
thing to note here, is just to clean up.

55
00:02:07,479 --> 00:02:10,660
Have a look in your imports. Now in my

56
00:02:10,660 --> 00:02:13,510
case, it's already removed, but if you

57
00:02:13,510 --> 00:02:15,130
haven't got Android Studio set up to do

58
00:02:15,130 --> 00:02:16,510
this automatically, you want to remove

59
00:02:16,510 --> 00:02:17,740
the unused

60
00:02:17,740 --> 00:02:20,160
ArrayAdapter import - the one that says

61
00:02:20,160 --> 00:02:22,480
android.widget.ArrayAdapter.

62
00:02:22,480 --> 00:02:24,100
And again, in my case, it's been removed

63
00:02:24,100 --> 00:02:26,110
because I've got Android Studio set up

64
00:02:26,110 --> 00:02:28,600
to automatically remove unused imports.

65
00:02:28,600 --> 00:02:30,850
Alright, going back to that code in

66
00:02:30,850 --> 00:02:33,670
onPostExecute again. Alright, so

67
00:02:33,670 --> 00:02:37,720
onPostExecute - onPostExecute - looking at

68
00:02:37,720 --> 00:02:39,160
that again, the other thing I want to do,

69
00:02:39,160 --> 00:02:41,230
I commented out these these two

70
00:02:41,230 --> 00:02:42,750
lines here in the previous video,

71
00:02:42,750 --> 00:02:45,010
relating to the older adapter, but I'm

72
00:02:45,010 --> 00:02:46,300
going to delete them completely now,

73
00:02:46,300 --> 00:02:48,040
because we've got a copy of that in the

74
00:02:48,040 --> 00:02:50,650
previous video's source code. And in the

75
00:02:50,650 --> 00:02:55,000
FeedAdapter class, let's remove the

76
00:02:55,000 --> 00:02:56,950
logging for that as well, and we can

77
00:02:56,950 --> 00:02:58,240
actually remove the TAG as well because

78
00:02:58,240 --> 00:02:59,580
we're no longer going to be using that.

79
00:02:59,580 --> 00:03:02,050
And the advantage of doing it that way

80
00:03:02,050 --> 00:03:04,960
is once I remove that line, it makes it

81
00:03:04,960 --> 00:03:07,030
quite easy for us to find any logging

82
00:03:07,030 --> 00:03:08,560
because it's now highlighted in red, as

83
00:03:08,560 --> 00:03:09,550
you can see. So I'm gonna go ahead and

84
00:03:09,550 --> 00:03:14,680
delete that. I think it's now using TAG

85
00:03:14,680 --> 00:03:16,000
from another class now, in case you're

86
00:03:16,000 --> 00:03:18,160
wondering why the red error hasn't

87
00:03:18,160 --> 00:03:19,720
disappeared. But we'll remove all those

88
00:03:19,720 --> 00:03:23,440
logging entries, and that should be it

89
00:03:23,440 --> 00:03:25,960
anyway. Okay, so that's the changes to

90
00:03:25,960 --> 00:03:29,290
our FeedAdapter, and check your

91
00:03:29,290 --> 00:03:31,840
imports at the top. I don't need to do

92
00:03:31,840 --> 00:03:33,430
anything here because, again, I've got

93
00:03:33,430 --> 00:03:34,680
mine set to automatically

94
00:03:34,680 --> 00:03:37,780
reconfigure unused imports, but there

95
00:03:37,780 --> 00:03:39,460
might be an android.util.log

96
00:03:39,460 --> 00:03:41,230
entry you can now delete as well, in

97
00:03:41,230 --> 00:03:44,860
the imports. Alright, so creating menus in

98
00:03:44,860 --> 00:03:46,330
previous versions of Android Studio

99
00:03:46,330 --> 00:03:49,780
before version 2.2, involved typing in

100
00:03:49,780 --> 00:03:52,810
the XML, but with version 2.2, Google

101
00:03:52,810 --> 00:03:55,120
included a menu designer, and that's

102
00:03:55,120 --> 00:03:56,440
actually still available in Android

103
00:03:56,440 --> 00:03:58,600
Studio 3. So let's actually see how it

104
00:03:58,600 --> 00:04:02,170
works, so we're going to open up our

105
00:04:02,170 --> 00:04:04,540
resource folder, on res folder, and open

106
00:04:04,540 --> 00:04:07,050
up our menu folder - there's a menu folder.

107
00:04:07,050 --> 00:04:09,160
Now there should be a menu folder, but

108
00:04:09,160 --> 00:04:10,750
depending on which template you used to

109
00:04:10,750 --> 00:04:12,760
create the project, you may or may not

110
00:04:12,760 --> 00:04:14,560
have a folder. So if you haven't got one,

111
00:04:14,560 --> 00:04:16,540
you want to actually create the new one.

112
00:04:16,540 --> 00:04:18,730
So, in the case of this particular

113
00:04:18,730 --> 00:04:20,920
project, I used the empty activity

114
00:04:20,920 --> 00:04:22,630
template when I created it, and that

115
00:04:22,630 --> 00:04:24,640
doesn't create a menu folder. But it

116
00:04:24,640 --> 00:04:26,050
isn't a problem, as I mentioned - we can

117
00:04:26,050 --> 00:04:28,090
actually create one. The templates just

118
00:04:28,090 --> 00:04:29,770
create a few of the files you need

119
00:04:29,770 --> 00:04:31,090
and, you know, really just

120
00:04:31,090 --> 00:04:32,770
to get you started, but you can do

121
00:04:32,770 --> 00:04:34,060
everything afterwards if you've chosen

122
00:04:34,060 --> 00:04:35,320
a template that doesn't include the

123
00:04:35,320 --> 00:04:37,660
feature you need. So in my case, I'm going to

124
00:04:37,660 --> 00:04:39,310
just click on the res folder, right-click,

125
00:04:39,310 --> 00:04:41,500
click on New, and I'm going to choose

126
00:04:41,500 --> 00:04:44,770
Android resource directory. Now the

127
00:04:44,770 --> 00:04:47,560
resource type, you want to set that to menu.

128
00:04:47,560 --> 00:04:49,360
When we do that, notice that the

129
00:04:49,360 --> 00:04:51,100
directory name changed automatically to

130
00:04:51,100 --> 00:04:53,110
menu as well. Everything else is fine,

131
00:04:53,110 --> 00:04:55,780
as is, so just click on OK. We've now got a

132
00:04:55,780 --> 00:04:57,060
menu folder, as you can see over here.

133
00:04:57,060 --> 00:04:59,710
And what we now need is a menu, so let's

134
00:04:59,710 --> 00:05:02,590
right-click the menu directory itself,

135
00:05:02,590 --> 00:05:05,530
click on New. We want to select New, Menu

136
00:05:05,530 --> 00:05:09,220
resource file, and for this one, this is

137
00:05:09,220 --> 00:05:10,660
going to be a list of the available feeds

138
00:05:10,660 --> 00:05:13,210
so I want to call it feeds underscore

139
00:05:13,210 --> 00:05:17,889
menu. Click on OK, and we're now in the

140
00:05:17,889 --> 00:05:20,080
menu designer, once that loads up. Now,

141
00:05:20,080 --> 00:05:22,539
once again, don't be afraid to experiment

142
00:05:22,539 --> 00:05:25,000
with the features of this designer. Once

143
00:05:25,000 --> 00:05:26,500
we've created our menu, I'm gonna be

144
00:05:26,500 --> 00:05:27,789
showing you how to make it appear in an

145
00:05:27,789 --> 00:05:29,919
app, so you can have a play creating

146
00:05:29,919 --> 00:05:31,210
menus, and just get, you know, really a

147
00:05:31,210 --> 00:05:34,000
feel for how the designer works. Now

148
00:05:34,000 --> 00:05:35,350
there are a few things different in this

149
00:05:35,350 --> 00:05:37,270
designer, when you're using it for menus

150
00:05:37,270 --> 00:05:40,240
rather than layouts. Now the obvious one

151
00:05:40,240 --> 00:05:41,950
is there's a much smaller

152
00:05:41,950 --> 00:05:43,539
choice of things to drag from the

153
00:05:43,539 --> 00:05:46,270
palette; just items, menus, groups and a

154
00:05:46,270 --> 00:05:47,110
couple of other things.

155
00:05:47,110 --> 00:05:49,030
Now another difference is that there's

156
00:05:49,030 --> 00:05:51,669
no blueprint, and no button to display it.

157
00:05:51,669 --> 00:05:54,039
Now menus don't have constraints, so all

158
00:05:54,039 --> 00:05:55,870
the buttons to do with constraints are

159
00:05:55,870 --> 00:05:58,419
also not present. Now another difference

160
00:05:58,419 --> 00:06:00,310
that isn't immediately obvious, is that

161
00:06:00,310 --> 00:06:02,169
you can make more use of the component

162
00:06:02,169 --> 00:06:03,460
tree when creating menus, and we're

163
00:06:03,460 --> 00:06:05,680
gonna be seeing that shortly. To start

164
00:06:05,680 --> 00:06:07,360
with though, I'm just gonna drag three of these

165
00:06:07,360 --> 00:06:09,520
menu thingies - these ones here, the menu

166
00:06:09,520 --> 00:06:11,650
item thingies. I'm not sure what Google's

167
00:06:11,650 --> 00:06:13,030
actually calling them, and one reason I'm

168
00:06:13,030 --> 00:06:15,039
encouraging you to experiment is that I

169
00:06:15,039 --> 00:06:16,979
still can't find any documentation.

170
00:06:16,979 --> 00:06:19,240
Menus themselves are documented, but

171
00:06:19,240 --> 00:06:21,060
all the examples still edit the XML.

172
00:06:21,060 --> 00:06:23,050
But anyway, let's just drag three of

173
00:06:23,050 --> 00:06:30,439
these menu items,

174
00:06:30,439 --> 00:06:32,899
as you can see me do there. I'll just

175
00:06:32,899 --> 00:06:34,849
drop them one below the other. Now

176
00:06:34,849 --> 00:06:36,559
don't worry too much about trying to

177
00:06:36,559 --> 00:06:38,689
place them anywhere in particular. Once

178
00:06:38,689 --> 00:06:40,249
your mouse pointer is over the design,

179
00:06:40,249 --> 00:06:42,439
it'll change from a no entry symbol

180
00:06:42,439 --> 00:06:43,789
to the symbol with a plus, which you

181
00:06:43,789 --> 00:06:45,499
probably saw - the green plus - and you can

182
00:06:45,499 --> 00:06:46,639
just let go at that point.

183
00:06:46,639 --> 00:06:49,129
And once you've got two items on the

184
00:06:49,129 --> 00:06:50,869
design, you can see a difference in

185
00:06:50,869 --> 00:06:52,279
behaviour. So it's possible to add the

186
00:06:52,279 --> 00:06:54,139
third one, either to the bottom of the

187
00:06:54,139 --> 00:06:56,569
other two or in between. And I'll just

188
00:06:56,569 --> 00:06:57,619
show you again - I'll just select another

189
00:06:57,619 --> 00:06:59,689
one. So you can select another one. Notice

190
00:06:59,689 --> 00:07:01,699
it's appearing in orange there, and I can

191
00:07:01,699 --> 00:07:03,619
move something, and go up and down - you

192
00:07:03,619 --> 00:07:05,389
can see the little blue line moving,

193
00:07:05,389 --> 00:07:07,159
or the green line, I should say, as to

194
00:07:07,159 --> 00:07:10,849
where it's going to go. And I'll put that

195
00:07:10,849 --> 00:07:13,069
back anyway, for now. Basically, the

196
00:07:13,069 --> 00:07:14,449
orange highlighting's to give you the feedback

197
00:07:14,449 --> 00:07:16,309
about what will happen. But at this stage,

198
00:07:16,309 --> 00:07:17,539
it doesn't really matter whether you add

199
00:07:17,539 --> 00:07:19,039
the third item to the end or in-between

200
00:07:19,039 --> 00:07:21,919
the existing ones, but obviously, that

201
00:07:21,919 --> 00:07:23,269
could matter if you're modifying an

202
00:07:23,269 --> 00:07:25,399
existing menu. But in my case, you saw me

203
00:07:25,399 --> 00:07:27,469
just add one after the other. So what I'm

204
00:07:27,469 --> 00:07:28,879
going to do first, is from the top I'm

205
00:07:28,879 --> 00:07:31,009
going to give them ID, give them both, or

206
00:07:31,009 --> 00:07:32,559
all, IDs. So I'm gonna select the top one,

207
00:07:32,559 --> 00:07:35,719
and we'll call this one a mnu - abbreviation

208
00:07:35,719 --> 00:07:39,769
for menu - then we'll put Free. The next

209
00:07:39,769 --> 00:07:45,740
one, we'll call that one a mnuPaid, and

210
00:07:45,740 --> 00:07:48,969
for the third one, will go with a mnu

211
00:07:48,969 --> 00:07:52,249
Songs. Well actually, I probably should have changed

212
00:07:52,249 --> 00:07:53,659
the titles as well, so let's go back and

213
00:07:53,659 --> 00:07:56,089
do that as well. so the title is going to

214
00:07:56,089 --> 00:08:00,979
be Free apps, for mnuFree. For the

215
00:08:00,979 --> 00:08:02,959
second one, we're going to go with Paid

216
00:08:02,959 --> 00:08:06,829
apps, and for the third one, we're going

217
00:08:06,829 --> 00:08:11,829
to go with, unsurprisingly, Songs. Okay.

218
00:08:11,829 --> 00:08:14,059
And we've got a warning here, about

219
00:08:14,059 --> 00:08:15,499
hard-coding strings, but we'll ignore

220
00:08:15,499 --> 00:08:17,419
that for now in the component tree. And

221
00:08:17,419 --> 00:08:19,099
that's really all we need to do at this

222
00:08:19,099 --> 00:08:21,229
stage. We will come back and look at some

223
00:08:21,229 --> 00:08:22,399
of the other things we can do in here,

224
00:08:22,399 --> 00:08:24,349
but for now, I just want to switch over

225
00:08:24,349 --> 00:08:27,469
to the XML version, or view I

226
00:08:27,469 --> 00:08:29,479
should say - the TextView - and reformat

227
00:08:29,479 --> 00:08:34,669
the code if it's needed. You can see,

228
00:08:34,669 --> 00:08:36,110
there's a slight change to reformatting when I

229
00:08:36,110 --> 00:08:37,729
did that. I'm going to switch back to

230
00:08:37,729 --> 00:08:42,960
Design, and I'm going to close the file.

231
00:08:42,960 --> 00:08:44,550
It's not necessary to switch back to

232
00:08:44,550 --> 00:08:46,110
Design, but Android Studio will open the

233
00:08:46,110 --> 00:08:48,060
file in the mode you last left it in, so in

234
00:08:48,060 --> 00:08:49,320
my case, I want to go back into Design

235
00:08:49,320 --> 00:08:51,150
made in the future. Alright, so I'm

236
00:08:51,150 --> 00:08:52,800
going to stop the video here. In the next

237
00:08:52,800 --> 00:08:54,360
one, we're going to work on adding the

238
00:08:54,360 --> 00:08:56,760
code to make these menus work. So I'll

239
00:08:56,760 --> 00:08:59,660
see you in the next video.

