1
00:00:04,779 --> 00:00:07,069
Alright, so the changes we need to make

2
00:00:07,069 --> 00:00:09,469
to the code are very simple. so you want

3
00:00:09,469 --> 00:00:11,389
to open up MainActivity.kt,

4
00:00:11,389 --> 00:00:13,059
which I've got opened up here now, and

5
00:00:13,059 --> 00:00:16,640
let's make those changes. Now we've seen

6
00:00:16,640 --> 00:00:19,070
how to add a synthetic import to let us

7
00:00:19,070 --> 00:00:21,669
refer to the layout's widgets directly,

8
00:00:21,669 --> 00:00:24,079
but when we did it before, we typed the

9
00:00:24,079 --> 00:00:26,210
import in manually. So this time, we're

10
00:00:26,210 --> 00:00:27,770
just going to use the widget and let

11
00:00:27,770 --> 00:00:29,750
Android Studio take care of the import

12
00:00:29,750 --> 00:00:31,790
for us. So we're going to be adding the

13
00:00:31,790 --> 00:00:34,040
code to the onPostExecute of our

14
00:00:34,040 --> 00:00:36,320
DownloadData class, and you can see, I've got that

15
00:00:36,320 --> 00:00:38,330
on the screen there. And this is where

16
00:00:38,330 --> 00:00:40,520
things get a little bit tricky. So I'm

17
00:00:40,520 --> 00:00:42,950
going to start first by adding, or

18
00:00:42,950 --> 00:00:45,020
creating rather, the ArrayAdapter. So I'm

19
00:00:45,020 --> 00:00:47,000
going to do that under this last line

20
00:00:47,000 --> 00:00:51,350
here, and I'm going to type val array

21
00:00:51,350 --> 00:00:59,000
Adapter equals ArrayAdapter. Then we

22
00:00:59,000 --> 00:01:00,649
need the diamond operator,

23
00:01:00,649 --> 00:01:06,850
FeedEntry, and then outside, parentheses.

24
00:01:06,850 --> 00:01:09,350
Now when we try to create the Array

25
00:01:09,350 --> 00:01:11,450
Adapter, Android Studio's suggesting that

26
00:01:11,450 --> 00:01:14,509
we have to provide a Context. Now a Context

27
00:01:14,509 --> 00:01:17,240
describes the application environment, or

28
00:01:17,240 --> 00:01:18,679
in the case of an Activity, the

29
00:01:18,679 --> 00:01:21,170
Activity's environment. Now it knows

30
00:01:21,170 --> 00:01:22,789
about things like the screen that the

31
00:01:22,789 --> 00:01:24,859
Activity is using, and all sorts of other

32
00:01:24,859 --> 00:01:27,889
configuration information. now the usual

33
00:01:27,889 --> 00:01:29,719
things to provide, when you have to use a

34
00:01:29,719 --> 00:01:31,819
Context inside an Activity, is a

35
00:01:31,819 --> 00:01:34,579
reference to the Activity instance. Now

36
00:01:34,579 --> 00:01:36,289
that would normally be this - the current

37
00:01:36,289 --> 00:01:38,479
Activity instance, but our code's not

38
00:01:38,479 --> 00:01:40,789
running in MainActivity - it's running in

39
00:01:40,789 --> 00:01:43,880
this nested DownloadData class. Now if

40
00:01:43,880 --> 00:01:46,039
we'd left downloadData as an inner class,

41
00:01:46,039 --> 00:01:48,409
we wouldn't have a problem. But if you

42
00:01:48,409 --> 00:01:50,270
recall, Android Studio persuaded us to

43
00:01:50,270 --> 00:01:52,670
make it a companion object - and that's

44
00:01:52,670 --> 00:01:53,990
this one here, the reference on

45
00:01:53,990 --> 00:01:56,869
line 40 - to avoid memory leaks. So as a

46
00:01:56,869 --> 00:01:58,789
result, we no longer have access to our

47
00:01:58,789 --> 00:02:01,490
containing MainActivity class. But okay,

48
00:02:01,490 --> 00:02:03,349
that's not the end of the world. What we

49
00:02:03,349 --> 00:02:05,810
can do, is we can pass in a reference to

50
00:02:05,810 --> 00:02:07,819
the MainActivity instance, when we

51
00:02:07,819 --> 00:02:10,758
create the DownloadData object. So let's

52
00:02:10,758 --> 00:02:13,099
see if that'll work. So we've got this

53
00:02:13,099 --> 00:02:15,980
reference here on line 41. So at the

54
00:02:15,980 --> 00:02:18,599
moment, we've got Async, as you can see

55
00:02:18,599 --> 00:02:20,670
there. We've got private class Download

56
00:02:20,670 --> 00:02:21,599
Data Async,

57
00:02:21,599 --> 00:02:23,400
then diamond bracket, diamond operator,

58
00:02:23,400 --> 00:02:26,819
String, Void, String. We can try changing

59
00:02:26,819 --> 00:02:28,980
that, so let's go ahead and put

60
00:02:28,980 --> 00:02:32,430
parentheses after the DownloadData, and

61
00:02:32,430 --> 00:02:35,400
in there we'll put Context : Context

62
00:02:35,400 --> 00:02:39,480
with a capital C, comma. Then ListView :

63
00:02:39,480 --> 00:02:41,340
ListView with a capital L and a

64
00:02:41,340 --> 00:02:45,329
capital V. Now if Android studio didn't

65
00:02:45,329 --> 00:02:47,909
add those imports automatically, like it

66
00:02:47,909 --> 00:02:49,590
did for me, just use Alt-Enter to get

67
00:02:49,590 --> 00:02:51,719
the imports added. But in my case,

68
00:02:51,719 --> 00:02:53,250
because I've configured Android

69
00:02:53,250 --> 00:02:55,139
Studio that way, it's automatically added

70
00:02:55,139 --> 00:02:58,709
the imports. Now we're going to use the Context

71
00:02:58,709 --> 00:03:01,169
and ListView in our class functions, so

72
00:03:01,169 --> 00:03:02,939
we need to provide backing fields for

73
00:03:02,939 --> 00:03:04,980
them both. So we're going to do that down

74
00:03:04,980 --> 00:03:08,819
below the tag line here, on line 44. And

75
00:03:08,819 --> 00:03:10,109
by the way, we'll talk about this towards

76
00:03:10,109 --> 00:03:11,250
the end of the video - this little pop-up

77
00:03:11,250 --> 00:03:12,750
in the corner - because you'll probably

78
00:03:12,750 --> 00:03:15,120
get that from time to time. So we're

79
00:03:15,120 --> 00:03:19,079
going to type, on line 46, var prop

80
00:03:19,079 --> 00:03:23,729
Context : Context, with a capital C, equals

81
00:03:23,729 --> 00:03:29,310
context. Then var,and I'll call this one prop

82
00:03:29,310 --> 00:03:33,139
ListView : space ListView

83
00:03:33,139 --> 00:03:40,379
equals little listView - you fix the typo. Now I

84
00:03:40,379 --> 00:03:41,639
don't recommend this naming convention,

85
00:03:41,639 --> 00:03:43,769
by the way. I've just made it up - but I

86
00:03:43,769 --> 00:03:44,790
want to be clear about what we're

87
00:03:44,790 --> 00:03:45,629
referring to,

88
00:03:45,629 --> 00:03:47,579
so I've prefixed both these backing

89
00:03:47,579 --> 00:03:50,609
properties with the word prop. But please

90
00:03:50,609 --> 00:03:51,359
don't do this.

91
00:03:51,359 --> 00:03:53,340
I've done it so there's no confusion

92
00:03:53,340 --> 00:03:55,169
between the properties and the

93
00:03:55,169 --> 00:03:56,849
parameters passed into the class to

94
00:03:56,849 --> 00:03:59,069
initialize them. Alright, at this

95
00:03:59,069 --> 00:04:00,209
point though, we've actually got some

96
00:04:00,209 --> 00:04:01,620
warnings - we've got some warnings

97
00:04:01,620 --> 00:04:05,120
over here - and we've also got an error.

98
00:04:05,120 --> 00:04:07,889
And we've still got an error, both there,

99
00:04:07,889 --> 00:04:09,449
which we looked at previously,

100
00:04:09,449 --> 00:04:10,829
which we were addressing, and we've also

101
00:04:10,829 --> 00:04:14,219
got another error, up here, relating now

102
00:04:14,219 --> 00:04:17,699
to line 37, and the call to the

103
00:04:17,699 --> 00:04:21,000
DownloadData function. So the first one

104
00:04:21,000 --> 00:04:22,560
on line 37 - well that's just because we

105
00:04:22,560 --> 00:04:24,750
changed the declaration of DownloadData

106
00:04:24,750 --> 00:04:26,370
but we haven't passed anything to it.

107
00:04:26,370 --> 00:04:28,469
Let's go ahead and change that first, so I'll

108
00:04:28,469 --> 00:04:31,380
up to here on line 37, and what we'll do is,

109
00:04:31,380 --> 00:04:32,340
we'll add this

110
00:04:32,340 --> 00:04:34,230
as the first argument and a comma

111
00:04:34,230 --> 00:04:37,290
space. Then XML ListView as the second

112
00:04:37,290 --> 00:04:39,260
argument, and that should fix that error up.

113
00:04:39,260 --> 00:04:41,430
And you saw that when I

114
00:04:41,430 --> 00:04:43,380
referred to XML ListView, Android Studio

115
00:04:43,380 --> 00:04:46,080
adds the synthetic import for us, and

116
00:04:46,080 --> 00:04:48,120
that lets us refer to any of the IDs in

117
00:04:48,120 --> 00:04:49,740
the layout, without having to keep

118
00:04:49,740 --> 00:04:51,990
calling findViewById, which obviously, is

119
00:04:51,990 --> 00:04:54,810
good. Alright, so that's fixed one of

120
00:04:54,810 --> 00:04:55,919
the errors but I've still got this

121
00:04:55,919 --> 00:04:57,630
option here, this error here - Array

122
00:04:57,630 --> 00:04:59,400
Adapter - which we need to address. We've

123
00:04:59,400 --> 00:05:02,130
also got these warnings as well. Now

124
00:05:02,130 --> 00:05:03,780
remember that the only reason we changed

125
00:05:03,780 --> 00:05:05,760
Downloaddata from an inner class to a

126
00:05:05,760 --> 00:05:08,460
companion object, was to avoid leaks. And

127
00:05:08,460 --> 00:05:11,669
if we have a look at these warnings, the

128
00:05:11,669 --> 00:05:14,490
field leaks a context object. Well we can

129
00:05:14,490 --> 00:05:15,810
see the first one; propContext is

130
00:05:15,810 --> 00:05:17,639
never used, but the second warning; This

131
00:05:17,639 --> 00:05:20,880
field leaks a context object. Now if your

132
00:05:20,880 --> 00:05:22,919
Asynctask doesn't have to update the

133
00:05:22,919 --> 00:05:24,600
User interface, then by all means use one.

134
00:05:24,600 --> 00:05:27,570
If you do have to update the UI - as we do

135
00:05:27,570 --> 00:05:29,910
here - then I'd suggest using an alternative

136
00:05:29,910 --> 00:05:31,830
approach, and we'll see that one in a

137
00:05:31,830 --> 00:05:33,870
little while. But first, though, let's see if we

138
00:05:33,870 --> 00:05:36,360
get this working. So what we can do, is we

139
00:05:36,360 --> 00:05:37,950
can avoid these leaks by using a

140
00:05:37,950 --> 00:05:40,260
delegate, which will result in only weak

141
00:05:40,260 --> 00:05:43,169
references to the context being held. So

142
00:05:43,169 --> 00:05:44,370
we can come back up here to our line

143
00:05:44,370 --> 00:05:47,520
again, there, propcontext colon context.

144
00:05:47,520 --> 00:05:50,940
then we can put, after the word Context,

145
00:05:50,940 --> 00:05:58,289
by delegates.notNull, like so, with

146
00:05:58,289 --> 00:06:02,039
parentheses. And we can do the same on

147
00:06:02,039 --> 00:06:04,919
the next line. So there, propListView :

148
00:06:04,919 --> 00:06:07,849
ListView equals, and we'll change that to

149
00:06:07,849 --> 00:06:11,479
Delegates.notNull

150
00:06:11,479 --> 00:06:16,590
in parentheses. And of course, I need the

151
00:06:16,590 --> 00:06:23,850
word by, as well - by Delegates - to fix that,

152
00:06:23,850 --> 00:06:26,460
and get rid of the equals. So, we've Context by

153
00:06:26,460 --> 00:06:28,920
Delegates.notNull, parentheses, and 

154
00:06:28,920 --> 00:06:30,660
ListView by Delegates.notNull.

155
00:06:30,660 --> 00:06:33,450
parentheses. So that should fix the

156
00:06:33,450 --> 00:06:35,190
warnings. We're now only getting the

157
00:06:35,190 --> 00:06:37,230
warnings now about the fact that they're

158
00:06:37,230 --> 00:06:38,670
never used, and which is correct at the

159
00:06:38,670 --> 00:06:40,080
moment. But we've also got this other

160
00:06:40,080 --> 00:06:42,990
error to fix down here, as well. But firstly,

161
00:06:42,990 --> 00:06:45,780
what we need to do now, is give our

162
00:06:45,780 --> 00:06:47,670
properties, given values. So we need to add

163
00:06:47,670 --> 00:06:49,500
an initialization block to assign the

164
00:06:49,500 --> 00:06:52,050
arguments to our properties. We can go

165
00:06:52,050 --> 00:06:54,530
ahead and do that, just under there.

166
00:06:54,530 --> 00:06:59,640
We can type init and add a code block,

167
00:06:59,640 --> 00:07:01,380
and within there, we can type prop

168
00:07:01,380 --> 00:07:05,670
Context equals context. Then on the next

169
00:07:05,670 --> 00:07:08,310
line, we can type propListView equals

170
00:07:08,310 --> 00:07:11,060
listView.

171
00:07:11,060 --> 00:07:13,350
Okay, so that's now initialized them as

172
00:07:13,350 --> 00:07:15,240
well, and you can see that the warning's

173
00:07:15,240 --> 00:07:17,190
now disappeared because they are actually

174
00:07:17,190 --> 00:07:18,510
being used and have been initialized

175
00:07:18,510 --> 00:07:20,820
correctly. So that's cleared the warnings

176
00:07:20,820 --> 00:07:22,920
and now we can complete the creation of

177
00:07:22,920 --> 00:07:24,720
our ArrayAdapter, because obviously

178
00:07:24,720 --> 00:07:27,060
that's still showing an error here. So we

179
00:07:27,060 --> 00:07:28,370
can change that to Val arrayAdapter

180
00:07:28,370 --> 00:07:31,200
equals - and we'll change that to adapter

181
00:07:31,200 --> 00:07:34,110
with an e - and it equals ArrayAdapter,

182
00:07:34,110 --> 00:07:36,330
then it's FeedEntry, and within the

183
00:07:36,330 --> 00:07:37,920
parentheses, now, we want to update this.

184
00:07:37,920 --> 00:07:42,990
I'm going to type propContext comma R

185
00:07:42,990 --> 00:07:47,120
dot layout.list_item

186
00:07:47,120 --> 00:07:50,580
comma space, and it's going to be parseAppilcations

187
00:07:50,580 --> 00:07:55,110
dot Applications, and obviously, the right

188
00:07:55,110 --> 00:07:57,750
parenthesis as well. And you can see now,

189
00:07:57,750 --> 00:07:59,970
that the error has disappeared. We have

190
00:07:59,970 --> 00:08:01,890
got a warning here, just that the fact

191
00:08:01,890 --> 00:08:03,270
that the arrayAdapter's not used but

192
00:08:03,270 --> 00:08:05,580
that's okay for the moment. So, this

193
00:08:05,580 --> 00:08:08,310
definition works but it's a bit messy.

194
00:08:08,310 --> 00:08:11,310
It's also not very readable and not

195
00:08:11,310 --> 00:08:13,170
immediately obvious what exactly will

196
00:08:13,170 --> 00:08:15,840
happen, if our Activity's destroyed while

197
00:08:15,840 --> 00:08:18,390
the AsyncTask's still running. So I'm

198
00:08:18,390 --> 00:08:20,520
going to deal with that shortly. Now our

199
00:08:20,520 --> 00:08:23,430
data, if you recall, is an ArrayList which

200
00:08:23,430 --> 00:08:25,320
we can get from the ParseApplications

201
00:08:25,320 --> 00:08:27,470
class by using its applications property.

202
00:08:27,470 --> 00:08:29,700
So we can see it if we go back to our

203
00:08:29,700 --> 00:08:33,360
ParseApplications and look at our

204
00:08:33,360 --> 00:08:34,610
ArrayList.

205
00:08:34,610 --> 00:08:37,020
The ArrayList that contains, over here,

206
00:08:37,020 --> 00:08:37,380
the

207
00:08:37,380 --> 00:08:40,650
list of applications we parsed out of

208
00:08:40,650 --> 00:08:43,110
the XML data. So all that really remains

209
00:08:43,110 --> 00:08:45,150
to do, is connect the data to the

210
00:08:45,150 --> 00:08:47,970
ListView. Let's go back to our Main

211
00:08:47,970 --> 00:08:51,300
Activity again, then on the line

212
00:08:51,300 --> 00:08:53,820
following that val ArrayAdapter, we're

213
00:08:53,820 --> 00:08:58,910
going to type propListView.adapter

214
00:08:58,910 --> 00:09:03,870
equals arrayadapter. And you can see all

215
00:09:03,870 --> 00:09:05,250
the warnings and errors have disappeared

216
00:09:05,250 --> 00:09:07,830
now. So we create a new Arrayadapter

217
00:09:07,830 --> 00:09:10,590
object. Now that needs three arguments -

218
00:09:10,590 --> 00:09:13,770
this is this code here on line 62, I'm

219
00:09:13,770 --> 00:09:16,170
talking about. The first is the Context. Now

220
00:09:16,170 --> 00:09:18,510
I'm going to talk about Context a bit

221
00:09:18,510 --> 00:09:20,550
later, because it's probably a good idea

222
00:09:20,550 --> 00:09:22,950
to see this working first. For now, though,

223
00:09:22,950 --> 00:09:24,480
we're just gonna pass in this instance

224
00:09:24,480 --> 00:09:27,870
of MainActivity - this propContext. Now

225
00:09:27,870 --> 00:09:29,640
the second parameter is the resource,

226
00:09:29,640 --> 00:09:32,430
containing the TextView that the Array

227
00:09:32,430 --> 00:09:34,470
Adapter will use to put the data into.

228
00:09:34,470 --> 00:09:36,810
Now if you recall, we created that in the

229
00:09:36,810 --> 00:09:38,430
layout file list_item dot

230
00:09:38,430 --> 00:09:41,130
xml, and so therefore, I'm passing

231
00:09:41,130 --> 00:09:44,310
R.layout.list_item for

232
00:09:44,310 --> 00:09:46,260
the resource argument, to link those two

233
00:09:46,260 --> 00:09:48,660
together. Now the third thing it needs is

234
00:09:48,660 --> 00:09:51,330
the list of objects to display, and

235
00:09:51,330 --> 00:09:54,450
over here, we're using the applications

236
00:09:54,450 --> 00:09:56,340
property of our parseApplications

237
00:09:56,340 --> 00:09:58,620
instance, to provide the ArrayList of

238
00:09:58,620 --> 00:10:00,990
FeedEntry objects. So the only other

239
00:10:00,990 --> 00:10:03,690
thing to do, is use the ListView's set

240
00:10:03,690 --> 00:10:06,510
Adapter method, to tell it the adapter it

241
00:10:06,510 --> 00:10:09,210
should use to get its data - and that's all

242
00:10:09,210 --> 00:10:09,930
there is to it.

243
00:10:09,930 --> 00:10:11,730
You add a ListView widget to your layout,

244
00:10:11,730 --> 00:10:15,150
you create a TextView resource, create an

245
00:10:15,150 --> 00:10:17,370
instance of an Adapter, and then call the

246
00:10:17,370 --> 00:10:18,810
setAdaptor function to link the

247
00:10:18,810 --> 00:10:20,730
ListView to the Adapter. You can see

248
00:10:20,730 --> 00:10:22,680
we're doing it here, by just setting the

249
00:10:22,680 --> 00:10:25,620
property directly in Kotlin to achieve

250
00:10:25,620 --> 00:10:27,870
that. And what we should be able to find

251
00:10:27,870 --> 00:10:30,540
now is, if we run this application, we

252
00:10:30,540 --> 00:10:32,490
should find that the Top 10 Free

253
00:10:32,490 --> 00:10:33,870
Applications will be displayed in a

254
00:10:33,870 --> 00:10:36,360
scrollable list. Alright, just before I start though,

255
00:10:36,360 --> 00:10:38,730
I just wanted to briefly open up our

256
00:10:38,730 --> 00:10:41,460
emulators, and to let you know that I'm

257
00:10:41,460 --> 00:10:45,720
now using the Nexus 5X API 26, and I'm

258
00:10:45,720 --> 00:10:47,370
using the Google Play version of that.

259
00:10:47,370 --> 00:10:49,110
Now there's a few reasons for that.

260
00:10:49,110 --> 00:10:50,850
Firstly, you noticed in a previous video, if

261
00:10:50,850 --> 00:10:51,240
you

262
00:10:51,240 --> 00:10:52,410
recall, there were lots of errors

263
00:10:52,410 --> 00:10:54,899
relating to my emulator. So by switching

264
00:10:54,899 --> 00:10:58,230
to a Nexus 5X, which is more

265
00:10:58,230 --> 00:10:59,970
appropriate anyway, because a Nexus 4

266
00:10:59,970 --> 00:11:01,860
doesn't run the latest version of

267
00:11:01,860 --> 00:11:04,020
Android anyway - so even in an emulator, it

268
00:11:04,020 --> 00:11:06,660
makes sense to use a new version. But the

269
00:11:06,660 --> 00:11:08,339
Nexus 5x is also good because it

270
00:11:08,339 --> 00:11:11,190
supports Google Play API's, and that's

271
00:11:11,190 --> 00:11:13,110
really useful for testing applications

272
00:11:13,110 --> 00:11:15,450
that are using Google Play. So I suggest

273
00:11:15,450 --> 00:11:18,240
you switch to that emulator, and just to

274
00:11:18,240 --> 00:11:19,800
give you a bit of a lowdown on that, the

275
00:11:19,800 --> 00:11:21,060
other thing I'd recommend - we'll just go

276
00:11:21,060 --> 00:11:23,430
back into Tools briefly, then go into

277
00:11:23,430 --> 00:11:27,540
Android and go into to SDK manager, the other

278
00:11:27,540 --> 00:11:29,370
thing I didn't make sure that I had set,

279
00:11:29,370 --> 00:11:32,040
and click on Show Package Details over

280
00:11:32,040 --> 00:11:34,620
here. Then notice that under Android 8

281
00:11:34,620 --> 00:11:38,010
Oreo, I've got the Google Play Intel x86

282
00:11:38,010 --> 00:11:39,899
Atom System Image. So you want to make

283
00:11:39,899 --> 00:11:41,970
sure you're using that one and not the

284
00:11:41,970 --> 00:11:44,520
API - the Google APIs - because the Google

285
00:11:44,520 --> 00:11:46,890
Play one gives you that extra option to

286
00:11:46,890 --> 00:11:49,560
run the Google Play apps, or apps that

287
00:11:49,560 --> 00:11:50,910
support or use Google Play

288
00:11:50,910 --> 00:11:53,910
functionality, and that's very useful. So,

289
00:11:53,910 --> 00:11:55,770
the other thing to keep in mind - I'm

290
00:11:55,770 --> 00:11:56,850
going to cancel out of that now, though,

291
00:11:56,850 --> 00:11:58,950
going back into the emulators - there's

292
00:11:58,950 --> 00:12:00,930
only a few devices that can actually run

293
00:12:00,930 --> 00:12:04,200
this Google Play version of an emulator.

294
00:12:04,200 --> 00:12:07,050
Nexus 5x is one, and I think Nexus 5 is

295
00:12:07,050 --> 00:12:09,120
another one. Most likely, when the new

296
00:12:09,120 --> 00:12:11,579
pixel devices get released by Android,

297
00:12:11,579 --> 00:12:12,930
you'll probably find they'll run it as

298
00:12:12,930 --> 00:12:14,910
well. But if you're trying to set this

299
00:12:14,910 --> 00:12:17,279
Google Play emulator,

300
00:12:17,279 --> 00:12:19,170
this particular version, on another

301
00:12:19,170 --> 00:12:21,180
device, more than likely it won't work in

302
00:12:21,180 --> 00:12:23,190
an emulator,so just keep that in mind. So

303
00:12:23,190 --> 00:12:24,720
in my case, what I've done is I'm using

304
00:12:24,720 --> 00:12:27,209
the Nexus 5x from now on, and I'll use

305
00:12:27,209 --> 00:12:30,600
that for all future emulator tasks in

306
00:12:30,600 --> 00:12:32,820
this course, and I've actually got that

307
00:12:32,820 --> 00:12:34,950
running now, as you can see there. Al

308
00:12:34,950 --> 00:12:36,899
right, so let's now try running this and

309
00:12:36,899 --> 00:12:42,450
see what happens. OK, running on the Nexus

310
00:12:42,450 --> 00:12:47,170
5x - let's have a look at it.

311
00:12:47,170 --> 00:12:49,850
Okay, you can see there's our applications -

312
00:12:49,850 --> 00:12:51,560
our 10 applications - appearing in the

313
00:12:51,560 --> 00:12:53,240
list, and you can notice that I can

314
00:12:53,240 --> 00:12:55,490
scroll them up and down now. So we're in

315
00:12:55,490 --> 00:12:57,589
the scrollable ListView and things are

316
00:12:57,589 --> 00:13:00,500
working nicely. Now if I go back to our

317
00:13:00,500 --> 00:13:03,110
code - go back to Main Activity. If I change

318
00:13:03,110 --> 00:13:06,230
the limit from 10 to 25 in the URL -

319
00:13:06,230 --> 00:13:07,970
that's this one here on line 40. So come

320
00:13:07,970 --> 00:13:11,779
over here and change that to 25, and run

321
00:13:11,779 --> 00:13:17,600
our app again, we'll actually see the 25

322
00:13:17,600 --> 00:13:20,510
apps instead of the top 10. So you can see

323
00:13:20,510 --> 00:13:22,220
the list, now, is actually longer than

324
00:13:22,220 --> 00:13:26,149
what the top 10 was before. So we still

325
00:13:26,149 --> 00:13:27,770
have the ones that we had before but you

326
00:13:27,770 --> 00:13:28,940
can see that I'm scrolling down further

327
00:13:28,940 --> 00:13:30,709
now, and getting access to other apps as

328
00:13:30,709 --> 00:13:31,070
well.

329
00:13:31,070 --> 00:13:33,980
So that's clearly more than 10 apps. So the

330
00:13:33,980 --> 00:13:36,110
ListView is able to support a variable

331
00:13:36,110 --> 00:13:38,510
number of items to be shown. So you don't

332
00:13:38,510 --> 00:13:40,070
have to change any code to make it

333
00:13:40,070 --> 00:13:41,750
display more records, if you've got more

334
00:13:41,750 --> 00:13:44,720
records to display. Alright, so let's

335
00:13:44,720 --> 00:13:46,100
finish the video here, but before I do

336
00:13:46,100 --> 00:13:47,930
that, if you do get these updates, and

337
00:13:47,930 --> 00:13:49,940
they will come through from time to time,

338
00:13:49,940 --> 00:13:51,500
I suggest you actually go ahead and

339
00:13:51,500 --> 00:13:53,209
install them. To do that, you can just

340
00:13:53,209 --> 00:13:55,910
click on Install, and depending on when

341
00:13:55,910 --> 00:13:57,470
you're watching this, Android Studio is

342
00:13:57,470 --> 00:13:59,029
getting smarter and smarter with Kotlin

343
00:13:59,029 --> 00:14:00,950
code and giving the ability to do this

344
00:14:00,950 --> 00:14:03,770
automatically. So click on Install and it

345
00:14:03,770 --> 00:14:05,300
should download and install that for us,

346
00:14:05,300 --> 00:14:07,250
and that's just enhancements to Kotlin

347
00:14:07,250 --> 00:14:10,010
and to the plugin, and to the language. 

348
00:14:10,010 --> 00:14:11,480
We'll then need to restart to activate

349
00:14:11,480 --> 00:14:21,550
the changes,

350
00:14:21,550 --> 00:14:23,780
and as you can see, it's indexing, which

351
00:14:23,780 --> 00:14:25,040
it'll do for the first time with a

352
00:14:25,040 --> 00:14:31,590
new version. But all our code is there, and

353
00:14:31,590 --> 00:14:33,640
if you do get a message like this,

354
00:14:33,640 --> 00:14:35,590
then click on this and click on Update

355
00:14:35,590 --> 00:14:40,540
Runtime. And again, depending on where we

356
00:14:40,540 --> 00:14:42,100
are and what the status is with Android

357
00:14:42,100 --> 00:14:43,660
Studio, this could be an automatic thing.

358
00:14:43,660 --> 00:14:45,670
But you can see that Automatic library

359
00:14:45,670 --> 00:14:47,980
version update for Gradle projects is

360
00:14:47,980 --> 00:14:49,630
currently unsupported, and that's

361
00:14:49,630 --> 00:14:51,100
relating to Kotlin. You'd find if this was

362
00:14:51,100 --> 00:14:53,160
Java, that would actually be working

363
00:14:53,160 --> 00:14:55,300
automatically. So you may not get this by

364
00:14:55,300 --> 00:14:56,620
the time you get around to seeing this,

365
00:14:56,620 --> 00:14:59,110
but if this does come up, close it down,

366
00:14:59,110 --> 00:15:01,660
click on the event log. We can see here

367
00:15:01,660 --> 00:15:04,210
that it says your version of Kotlin

368
00:15:04,210 --> 00:15:06,100
runtime is Kotlin STD, but

369
00:15:06,100 --> 00:15:07,720
basically, the important part is these

370
00:15:07,720 --> 00:15:10,510
numbers here; 1 1 4 3, or plugin version 1

371
00:15:10,510 --> 00:15:12,780
1 5 0. So, you just take these numbers,

372
00:15:12,780 --> 00:15:16,420
obviously, 1.1.50 is greater than

373
00:15:16,420 --> 00:15:19,810
1.1.4 - 3, so I'm gonna copy the 1 1

374
00:15:19,810 --> 00:15:22,420
5 0. I'm going to close down the event

375
00:15:22,420 --> 00:15:25,030
log, then I'm gonna open my Gradle scripts.

376
00:15:25,030 --> 00:15:26,530
I'm gonna click on this first

377
00:15:26,530 --> 00:15:28,930
build.gradle. You can see where it's got

378
00:15:28,930 --> 00:15:31,960
ext.kotlin_version equals 1.1 point

379
00:15:31,960 --> 00:15:34,810
4 - 3. I'm gonna change that

380
00:15:34,810 --> 00:15:38,620
to the newer number, and for some reason

381
00:15:38,620 --> 00:15:39,670
that didn't copy. I'll just try it again -

382
00:15:39,670 --> 00:15:40,500
copy. If

383
00:15:40,500 --> 00:15:42,670
it doesn't copy I'll just type it in.

384
00:15:42,670 --> 00:15:45,790
We'll close off the event log again, back

385
00:15:45,790 --> 00:15:49,930
into here and paste it. Let's go. That's

386
00:15:49,930 --> 00:15:51,490
better this time, and click on Sync Now,

387
00:15:51,490 --> 00:15:54,760
and that should actually now update our

388
00:15:54,760 --> 00:15:56,500
project to be using the latest version

389
00:15:56,500 --> 00:15:59,080
of Kotlin. And you can see down the bottom,

390
00:15:59,080 --> 00:16:00,520
it's working away and downloading what

391
00:16:00,520 --> 00:16:02,470
it needs to make that happen. And the

392
00:16:02,470 --> 00:16:04,120
downloads are generally a once-off

393
00:16:04,120 --> 00:16:06,670
process, so you can find

394
00:16:06,670 --> 00:16:07,930
that it takes a while the first time but

395
00:16:07,930 --> 00:16:10,150
then once that's done, it's downloaded

396
00:16:10,150 --> 00:16:12,100
and these relevant files are on your

397
00:16:12,100 --> 00:16:14,530
computer, and subsequent to compilation

398
00:16:14,530 --> 00:16:16,510
and opening projects etc will be a lot

399
00:16:16,510 --> 00:16:20,290
faster.

400
00:16:20,290 --> 00:16:22,190
Alright, so you can see it's finally

401
00:16:22,190 --> 00:16:23,360
finished then, and we can just test that.

402
00:16:23,360 --> 00:16:24,350
We can actually close down the project

403
00:16:24,350 --> 00:16:27,350
and open it again, and this time we shouldn't

404
00:16:27,350 --> 00:16:30,590
get any warnings. You can see it's now happy,

405
00:16:30,590 --> 00:16:33,140
and I can close down the build Gradle

406
00:16:33,140 --> 00:16:34,370
script now because we're now

407
00:16:34,370 --> 00:16:36,440
running the latest version. Alright, so

408
00:16:36,440 --> 00:16:38,420
let's finish the video here now. So in the

409
00:16:38,420 --> 00:16:39,740
next video, we'll start having a

410
00:16:39,740 --> 00:16:41,690
look at the interface because, obviously,

411
00:16:41,690 --> 00:16:43,340
it wasn't terribly pretty - if we go back

412
00:16:43,340 --> 00:16:45,350
and have a quick look at it. Actually,

413
00:16:45,350 --> 00:16:52,269
we'll just run it again.

414
00:16:52,269 --> 00:16:54,309
So as you can see, it's not terribly

415
00:16:54,309 --> 00:16:55,749
pretty but we'll have a look at seeing

416
00:16:55,749 --> 00:16:58,209
what we can do, to make that a little bit

417
00:16:58,209 --> 00:17:01,290
nicer in the next video.

