1 00:00:04,700 --> 00:00:07,160 Alright, so we got the layout that our 2 00:00:07,160 --> 00:00:09,440 custom adapters going to use, so it's now 3 00:00:09,440 --> 00:00:12,019 time to create the adapter. So you want 4 00:00:12,019 --> 00:00:13,519 to open the project pane if it's closed, 5 00:00:13,519 --> 00:00:16,369 and right-click on the package and choose 6 00:00:16,369 --> 00:00:19,279 New Kotlin File/Class. We're going to 7 00:00:19,279 --> 00:00:24,439 call this one FeedAdapter, and I suggest 8 00:00:24,439 --> 00:00:27,200 you change the Kind to Class, just to 9 00:00:27,200 --> 00:00:30,489 save us a little bit of typing. Click OK. 10 00:00:30,489 --> 00:00:33,350 Now, we want to extend the ArrayAdapter 11 00:00:33,350 --> 00:00:35,809 class, and that's so that we'll have all 12 00:00:35,809 --> 00:00:37,190 the functionality of an ArrayAdapter, 13 00:00:37,190 --> 00:00:39,530 but we can then change some methods to 14 00:00:39,530 --> 00:00:41,210 deal with the more complicated view that 15 00:00:41,210 --> 00:00:43,430 we want to use. So to make our class 16 00:00:43,430 --> 00:00:47,210 extend the ArrayAdapter, we use the, we 17 00:00:47,210 --> 00:00:48,530 just declare it to be of type Array 18 00:00:48,530 --> 00:00:50,390 Adapter, using the normal Kotlin syntax. 19 00:00:50,390 --> 00:00:53,090 So it's colon after FeedAdapter, then it's 20 00:00:53,090 --> 00:00:56,780 ArrayAdapter, diamond operator, and it's 21 00:00:56,780 --> 00:01:00,560 going to be Feedentry, and that brings up an 22 00:01:00,560 --> 00:01:02,120 error, and the error here is saying This 23 00:01:02,120 --> 00:01:04,670 type has a constructor, and thus must be 24 00:01:04,670 --> 00:01:06,770 initialized here. So basically, it's 25 00:01:06,770 --> 00:01:07,820 telling us that we need to have a 26 00:01:07,820 --> 00:01:09,889 constructor. Let's just have a look at 27 00:01:09,889 --> 00:01:12,380 that link that I posted earlier. Open a 28 00:01:12,380 --> 00:01:17,630 browser and paste the link in. Now we're 29 00:01:17,630 --> 00:01:18,920 interested in the public constructors 30 00:01:18,920 --> 00:01:20,899 which is in this summary section here, 31 00:01:20,899 --> 00:01:22,789 and you can see that there's six 32 00:01:22,789 --> 00:01:25,100 constructors. So how do we know which one 33 00:01:25,100 --> 00:01:27,350 we want to use? Well it turns out our 34 00:01:27,350 --> 00:01:29,509 data is being stored in an ArrayList of 35 00:01:29,509 --> 00:01:31,850 FeedEntry objects, so the one that we 36 00:01:31,850 --> 00:01:35,209 want is this one here, the fifth one. But 37 00:01:35,209 --> 00:01:36,649 if that's not obvious, we're going to 38 00:01:36,649 --> 00:01:38,499 ignore it for now and see what happens. 39 00:01:38,499 --> 00:01:41,179 As you can see, though, all six 40 00:01:41,179 --> 00:01:44,179 constructors need at least a Context and 41 00:01:44,179 --> 00:01:46,609 a resource. Now the resource is the 42 00:01:46,609 --> 00:01:48,139 layout that we'll be using - our list 43 00:01:48,139 --> 00:01:50,810 _record.xml layout. So if 44 00:01:50,810 --> 00:01:52,609 all six constructors need at least two 45 00:01:52,609 --> 00:01:54,770 objects, or those two objects, we'll just 46 00:01:54,770 --> 00:01:56,810 include them for now, and then we'll pass 47 00:01:56,810 --> 00:01:58,579 them to our adapter in its Primary 48 00:01:58,579 --> 00:02:02,329 Constructor. So let's go back - go ahead 49 00:02:02,329 --> 00:02:09,318 and add a constructor. Alright, so what 50 00:02:09,318 --> 00:02:11,420 we need to do then is, come over here to 51 00:02:11,420 --> 00:02:14,980 class FeedAdapter and in parentheses, 52 00:02:14,980 --> 00:02:19,310 context colon space Context, 53 00:02:19,310 --> 00:02:25,170 and then we want to do val resource colon 54 00:02:25,170 --> 00:02:28,860 Int, and end of parentheses. Then still leave 55 00:02:28,860 --> 00:02:30,840 the colon and then the ArrayAdapter Feed 56 00:02:30,840 --> 00:02:33,599 Entry there. Now this, actually, still 57 00:02:33,599 --> 00:02:34,830 gives us an error that the type has a 58 00:02:34,830 --> 00:02:36,390 constructor and thus must be 59 00:02:36,390 --> 00:02:38,580 initialized here. So we're going to pass 60 00:02:38,580 --> 00:02:40,440 the two arguments that we get into our 61 00:02:40,440 --> 00:02:42,870 Primary Constructor, and we do that by adding 62 00:02:42,870 --> 00:02:49,400 parentheses on the end; context, resource. 63 00:02:49,400 --> 00:02:52,709 And that keeps things happy. Now we're 64 00:02:52,709 --> 00:02:54,780 going to add some logging later, to show 65 00:02:54,780 --> 00:02:56,579 what's happening, so let's add a tag for 66 00:02:56,579 --> 00:02:58,709 that. That's going to be private 67 00:02:58,709 --> 00:03:05,340 val TAG is equal to FeedAdaptor. Now the 68 00:03:05,340 --> 00:03:06,629 other thing we're going to have to do is 69 00:03:06,629 --> 00:03:09,420 inflate the xml resource to create the 70 00:03:09,420 --> 00:03:12,870 View. Now inflating an xml resource is 71 00:03:12,870 --> 00:03:15,690 just the term used to describe taking 72 00:03:15,690 --> 00:03:18,510 the xml representation, and producing the 73 00:03:18,510 --> 00:03:21,540 actual widgets from it. So the xml in our 74 00:03:21,540 --> 00:03:23,310 list_record.xml file 75 00:03:23,310 --> 00:03:25,829 describes the TextView widgets and their 76 00:03:25,829 --> 00:03:28,859 constraints, font sizes etc. So a Layout 77 00:03:28,859 --> 00:03:31,650 Inflator takes that xml, and inflates it 78 00:03:31,650 --> 00:03:33,750 to produce the View object that can be 79 00:03:33,750 --> 00:03:36,000 displayed on the screen. Now we get a 80 00:03:36,000 --> 00:03:37,889 LayoutInflater from a Context, and we've 81 00:03:37,889 --> 00:03:39,920 been given a context in the constructor. 82 00:03:39,920 --> 00:03:42,389 Now rather than retrieve the inflater 83 00:03:42,389 --> 00:03:45,000 each time we need it, we'll store it so 84 00:03:45,000 --> 00:03:47,099 that we can use it wherever we need it. 85 00:03:47,099 --> 00:03:48,930 So let's go ahead and do that with 86 00:03:48,930 --> 00:03:54,750 private val inflater equals, and it's 87 00:03:54,750 --> 00:03:58,190 going to be LayoutInflater.from 88 00:03:58,190 --> 00:04:02,310 parentheses context. Now there's that 89 00:04:02,310 --> 00:04:05,489 Context again. The Contexts are used 90 00:04:05,489 --> 00:04:07,530 extensively throughout the Android 91 00:04:07,530 --> 00:04:09,720 framework, especially when dealing with 92 00:04:09,720 --> 00:04:12,359 the user interface. Now we saw a context 93 00:04:12,359 --> 00:04:14,459 a couple of videos ago, but what is a 94 00:04:14,459 --> 00:04:17,339 context? So let's just start by having a 95 00:04:17,339 --> 00:04:18,988 look and seeing what the Google 96 00:04:18,988 --> 00:04:24,750 documentation has to say about it. 97 00:04:24,750 --> 00:04:28,490 Paste in a link. 98 00:04:28,490 --> 00:04:30,380 Now there's a couple of important things 99 00:04:30,380 --> 00:04:32,930 on this page. The first paragraph, as you can 100 00:04:32,930 --> 00:04:35,600 see here, explains that the context is an 101 00:04:35,600 --> 00:04:38,599 interface to global information about an 102 00:04:38,599 --> 00:04:40,880 application environment, and that it 103 00:04:40,880 --> 00:04:43,310 allows access to application specific 104 00:04:43,310 --> 00:04:45,979 resources and classes. So it, basically, 105 00:04:45,979 --> 00:04:47,780 holds the state of the application or 106 00:04:47,780 --> 00:04:51,080 activity while it's running. Now imagine 107 00:04:51,080 --> 00:04:53,060 you're the manager of a multi-screen 108 00:04:53,060 --> 00:04:55,970 cinema complex. When you decide to show a 109 00:04:55,970 --> 00:04:58,370 particular film, you need to know which 110 00:04:58,370 --> 00:05:00,979 screen to project it onto, so the screen 111 00:05:00,979 --> 00:05:03,800 forms part of the film's context. You 112 00:05:03,800 --> 00:05:05,449 also need to know what time to show it, 113 00:05:05,449 --> 00:05:07,190 and also how much to charge for the 114 00:05:07,190 --> 00:05:09,470 tickets. So again, these are part of the 115 00:05:09,470 --> 00:05:11,660 context for that particular screening of 116 00:05:11,660 --> 00:05:14,449 that particular film. So without access 117 00:05:14,449 --> 00:05:16,310 to the context, you wouldn't know which 118 00:05:16,310 --> 00:05:18,919 room or screen to show it in, or what 119 00:05:18,919 --> 00:05:22,190 time to show it. So a Context in Android 120 00:05:22,190 --> 00:05:24,650 serves a similar purpose. So it contains 121 00:05:24,650 --> 00:05:26,210 information on the things about an 122 00:05:26,210 --> 00:05:28,400 Application or an Activity, that the 123 00:05:28,400 --> 00:05:31,099 system needs in order to manage it. And 124 00:05:31,099 --> 00:05:33,710 it also provides access to the various 125 00:05:33,710 --> 00:05:36,199 classes that are needed, such as the Layout 126 00:05:36,199 --> 00:05:37,759 Inflater, that we'll be using. 127 00:05:37,759 --> 00:05:39,590 So let's actually have a quick look at 128 00:05:39,590 --> 00:05:41,659 the documentation for the LayoutInflater 129 00:05:41,659 --> 00:05:49,610 class. So a LayoutInflater 130 00:05:49,610 --> 00:05:52,639 instantiates a layout XML file into 131 00:05:52,639 --> 00:05:55,219 its corresponding View objects, which is 132 00:05:55,219 --> 00:05:56,900 really just a fancy way of saying that 133 00:05:56,900 --> 00:05:59,000 it creates all the View objects that's 134 00:05:59,000 --> 00:06:01,070 described in the xml. Now the 135 00:06:01,070 --> 00:06:03,740 documentation also states that you 136 00:06:03,740 --> 00:06:05,630 shouldn't create your own instance of a 137 00:06:05,630 --> 00:06:08,719 LayoutInflater. Instead, you should use 138 00:06:08,719 --> 00:06:10,880 getLayoutInflater or getSystem 139 00:06:10,880 --> 00:06:13,009 Service to get a standard Layout 140 00:06:13,009 --> 00:06:15,560 Inflater that's already hooked up to the 141 00:06:15,560 --> 00:06:17,690 current context, and correctly configured 142 00:06:17,690 --> 00:06:20,659 for the device you're running on. Now if 143 00:06:20,659 --> 00:06:22,880 we run our app on a tablet, it may return 144 00:06:22,880 --> 00:06:25,219 a different LayoutInflater than if we 145 00:06:25,219 --> 00:06:27,259 ran it on a phone or an emulator - we 146 00:06:27,259 --> 00:06:30,050 don't care. As long as we ask the context 147 00:06:30,050 --> 00:06:31,280 to provide us with an inflater, 148 00:06:31,280 --> 00:06:34,370 everything works fine. Now the important 149 00:06:34,370 --> 00:06:36,949 thing is that we need a context which we 150 00:06:36,949 --> 00:06:38,570 can, you know, request things like the 151 00:06:38,570 --> 00:06:41,630 layout inflater from. Now I've used the 152 00:06:41,630 --> 00:06:42,139 static 153 00:06:42,139 --> 00:06:44,150 LayoutInflater.from method - if we just go 154 00:06:44,150 --> 00:06:46,129 back and have a look at that - here on 155 00:06:46,129 --> 00:06:48,710 line 13. We use that particular 156 00:06:48,710 --> 00:06:50,300 function to get our LayoutInflater and 157 00:06:50,300 --> 00:06:51,830 then we pass the context as a 158 00:06:51,830 --> 00:06:54,379 parameter. So that just wraps a call to 159 00:06:54,379 --> 00:06:56,150 getSystemService with the correct 160 00:06:56,150 --> 00:06:57,979 parameters, and there's no difference 161 00:06:57,979 --> 00:06:59,840 between any of those three ways to get 162 00:06:59,840 --> 00:07:02,810 an inflater from a context. Now switching 163 00:07:02,810 --> 00:07:04,580 back to the documentation really briefly, 164 00:07:04,580 --> 00:07:09,379 for Context again, another interesting 165 00:07:09,379 --> 00:07:11,620 thing is the list of Known Subclasses. 166 00:07:11,620 --> 00:07:14,509 Because Activity and AppCompatActivity 167 00:07:14,509 --> 00:07:17,180 both extend the basic Context class, we 168 00:07:17,180 --> 00:07:18,830 can use the current instance of an 169 00:07:18,830 --> 00:07:20,840 activity, whenever we need to pass a 170 00:07:20,840 --> 00:07:23,539 context to our function. So you'll often 171 00:07:23,539 --> 00:07:26,599 see this or MainActivity.this used, 172 00:07:26,599 --> 00:07:28,460 when calling a method that needs a 173 00:07:28,460 --> 00:07:31,069 context. So you can see here like 174 00:07:31,069 --> 00:07:34,129 Activity and AppCompatActivity are 175 00:07:34,129 --> 00:07:37,370 both subclasses. Alright, so moving on. 176 00:07:37,370 --> 00:07:39,379 We'll go back to the Android Studio code 177 00:07:39,379 --> 00:07:41,930 again. So we've got a class that extends 178 00:07:41,930 --> 00:07:44,839 the ArrayAdapter. Now to make it work, 179 00:07:44,839 --> 00:07:47,150 we just need to override two functions 180 00:07:47,150 --> 00:07:48,379 of the base class. 181 00:07:48,379 --> 00:07:51,439 Now when the ListView Scrolls items off 182 00:07:51,439 --> 00:07:54,289 the screen, it'll ask its adapter for a 183 00:07:54,289 --> 00:07:56,719 new view to display, and it does this by 184 00:07:56,719 --> 00:07:59,330 calling the getView method. So that's 185 00:07:59,330 --> 00:08:00,770 the first method that we need to 186 00:08:00,770 --> 00:08:04,219 override. Now the ListView also needs to 187 00:08:04,219 --> 00:08:06,469 know how many items there are, so it 188 00:08:06,469 --> 00:08:08,210 knows things like how to represent the 189 00:08:08,210 --> 00:08:10,250 scroll bar, to indicate how far through 190 00:08:10,250 --> 00:08:12,050 the list that you've scrolled. Now 191 00:08:12,050 --> 00:08:14,479 to get the number of items, it uses the 192 00:08:14,479 --> 00:08:16,729 getCount method. Now there are 193 00:08:16,729 --> 00:08:18,379 other methods that we can override if 194 00:08:18,379 --> 00:08:20,330 we need to further customise the adapter, 195 00:08:20,330 --> 00:08:22,849 but these two are all we actually need 196 00:08:22,849 --> 00:08:25,189 at this stage - but these two are all that 197 00:08:25,189 --> 00:08:27,259 are actually required. So I'm going to 198 00:08:27,259 --> 00:08:29,870 get Android Studio to override those, 199 00:08:29,870 --> 00:08:32,599 to generate the basic functions for us. 200 00:08:32,599 --> 00:08:35,599 So it's basically the getView and get 201 00:08:35,599 --> 00:08:38,779 Count. So I'm going to select both of 202 00:08:38,779 --> 00:08:44,680 those and click on OK, 203 00:08:44,680 --> 00:08:46,630 and you can see they've both been overridden 204 00:08:46,630 --> 00:08:49,750 on the screen now. So starting off, the 205 00:08:49,750 --> 00:08:51,430 getCount method's going to be pretty 206 00:08:51,430 --> 00:08:52,990 easy because we just need to return the 207 00:08:52,990 --> 00:08:55,930 number of items in our list. So we come 208 00:08:55,930 --> 00:08:58,210 back to that - to getCount - and we do a 209 00:08:58,210 --> 00:09:06,459 return applications.size. Now that 210 00:09:06,459 --> 00:09:07,899 would work, except we don't have a list. 211 00:09:07,899 --> 00:09:10,779 Now we obviously need one, as it's our 212 00:09:10,779 --> 00:09:12,279 list of FeedEntry objects that'll 213 00:09:12,279 --> 00:09:15,250 provide the data to display. So going 214 00:09:15,250 --> 00:09:16,779 back to the documentation on the Array 215 00:09:16,779 --> 00:09:21,220 Adapter, let's have another look at these 216 00:09:21,220 --> 00:09:23,980 constructors. So the last four 217 00:09:23,980 --> 00:09:25,990 constructors all show a final 218 00:09:25,990 --> 00:09:28,330 parameter that's either an Array or a 219 00:09:28,330 --> 00:09:29,830 List. You can see these ones here - the T 220 00:09:29,830 --> 00:09:32,399 left and right square brackets are objects, 221 00:09:32,399 --> 00:09:35,230 or a list, as you can see there. It's 222 00:09:35,230 --> 00:09:37,089 either an Array or a List. Now we're 223 00:09:37,089 --> 00:09:39,520 using an ArrayList, which is a specific 224 00:09:39,520 --> 00:09:41,589 implementation of list, so the 225 00:09:41,589 --> 00:09:43,000 constructor we're interested in here, is 226 00:09:43,000 --> 00:09:45,670 really this fifth one. So therefore, we 227 00:09:45,670 --> 00:09:47,410 need to modify our class Primary 228 00:09:47,410 --> 00:09:49,600 Constructor, so we can pass in the 229 00:09:49,600 --> 00:09:51,010 ArrayList that's going to contain our 230 00:09:51,010 --> 00:09:54,160 data. So let's go back to a Android Studio 231 00:09:54,160 --> 00:09:56,410 and make a change here. So at the moment, 232 00:09:56,410 --> 00:09:58,209 we've got class FeedAdapter context 233 00:09:58,209 --> 00:10:01,330 Context, val resource Int. So let's go 234 00:10:01,330 --> 00:10:02,529 ahead and change that. So we're going to 235 00:10:02,529 --> 00:10:04,600 use the next one, and we're gonna add 236 00:10:04,600 --> 00:10:05,920 another argument which is going to be 237 00:10:05,920 --> 00:10:11,320 comma val applications : Then it's going 238 00:10:11,320 --> 00:10:14,760 to be List diamond operator FeedEntry - 239 00:10:14,760 --> 00:10:18,070 list of FeedEntry objects - and you saw 240 00:10:18,070 --> 00:10:19,900 that the error then disappears on line 241 00:10:19,900 --> 00:10:21,370 18, now that we've correctly 242 00:10:21,370 --> 00:10:23,920 specified that. Now if you're not sure 243 00:10:23,920 --> 00:10:25,870 which constructor you need in situations 244 00:10:25,870 --> 00:10:28,000 like this, start off with the minimum. 245 00:10:28,000 --> 00:10:30,160 And as you continue writing the code, 246 00:10:30,160 --> 00:10:31,390 you'll spot where you need to use a 247 00:10:31,390 --> 00:10:33,400 different one, just like we did here, and 248 00:10:33,400 --> 00:10:35,850 then you add that, and so on and so forth. 249 00:10:35,850 --> 00:10:38,230 Okay, now if you don't override the get 250 00:10:38,230 --> 00:10:40,390 Count method, the ListView won't display 251 00:10:40,390 --> 00:10:42,579 any records. It needs to know how many 252 00:10:42,579 --> 00:10:44,410 items there are so that it can create 253 00:10:44,410 --> 00:10:46,779 the list of rows. So if you create an 254 00:10:46,779 --> 00:10:48,730 adapter and just get a blank ListView, 255 00:10:48,730 --> 00:10:50,589 check to make sure that you've provided 256 00:10:50,589 --> 00:10:52,540 the correct count of the items in the 257 00:10:52,540 --> 00:10:54,220 getCount method, and you can see that 258 00:10:54,220 --> 00:10:56,829 we've done that here, on line 18. Al 259 00:10:56,829 --> 00:10:58,450 right, so the getView 260 00:10:58,450 --> 00:11:00,550 method's called by the ListView, every 261 00:11:00,550 --> 00:11:03,370 time it wants another item to display. So 262 00:11:03,370 --> 00:11:05,050 let's go through a very naive 263 00:11:05,050 --> 00:11:07,570 implementation to get started, so we've 264 00:11:07,570 --> 00:11:08,560 got something to work on. 265 00:11:08,560 --> 00:11:10,990 So I'm gonna get rid of the super.get 266 00:11:10,990 --> 00:11:14,430 View. We could do something like val view 267 00:11:14,430 --> 00:11:21,060 equals inflater.inflate resource 268 00:11:21,060 --> 00:11:25,030 parent false, and we'll just go through 269 00:11:25,030 --> 00:11:26,440 this code first and then talk about it. 270 00:11:26,440 --> 00:11:32,170 So val tvName : TextView is equal to view 271 00:11:32,170 --> 00:11:36,070 dot findViewById R.id.tv 272 00:11:36,070 --> 00:11:39,400 Name, and we can just take a copy of that 273 00:11:39,400 --> 00:11:40,690 and do that for the other two fields, so 274 00:11:40,690 --> 00:11:46,060 we also got tvArtist and we've also got 275 00:11:46,060 --> 00:11:54,670 tvSummary. 276 00:11:54,670 --> 00:11:57,320 Artist, and we could do something like val 277 00:11:57,320 --> 00:12:03,610 currentApp equals applications position. 278 00:12:03,610 --> 00:12:08,470 Then we could do tvName.text equals 279 00:12:08,470 --> 00:12:15,200 currentApp.name - not sure whether copying 280 00:12:15,200 --> 00:12:16,400 pasting is any quicker than just typing 281 00:12:16,400 --> 00:12:29,320 it - but Artist, Summary, summary, artist, 282 00:12:29,320 --> 00:12:37,190 then a return view, return view. So that's a very 283 00:12:37,190 --> 00:12:39,920 naive implementation, and it's also not 284 00:12:39,920 --> 00:12:42,410 very efficient, because we're creating a 285 00:12:42,410 --> 00:12:44,000 new view every time and having to call 286 00:12:44,000 --> 00:12:46,339 findViewById for each of the TextView 287 00:12:46,339 --> 00:12:48,620 widgets. Now we're going to modify this 288 00:12:48,620 --> 00:12:50,180 soon, but for now, we'll just get it 289 00:12:50,180 --> 00:12:52,400 working. Now notice that Android Studio 290 00:12:52,400 --> 00:12:57,410 is suggesting, over here, that we should 291 00:12:57,410 --> 00:12:59,930 use the View Holder pattern. So that's 292 00:12:59,930 --> 00:13:02,300 what we're going to do later. Alright, 293 00:13:02,300 --> 00:13:04,490 so what have we done here, though. Well the 294 00:13:04,490 --> 00:13:07,220 function starts off by creating a View - 295 00:13:07,220 --> 00:13:10,370 we're doing that on line 23. It does that 296 00:13:10,370 --> 00:13:12,890 by inflating the layout resource, and it 297 00:13:12,890 --> 00:13:14,570 uses the layoutInflater that we 298 00:13:14,570 --> 00:13:15,950 created from the Context in the 299 00:13:15,950 --> 00:13:18,710 constructor. So it then finds the three Text 300 00:13:18,710 --> 00:13:20,480 View widgets using the findViewById - 301 00:13:20,480 --> 00:13:22,510 lines 25 through 27. 302 00:13:22,510 --> 00:13:25,130 Now when the ListView calls this getView 303 00:13:25,130 --> 00:13:27,410 method, it tells it the position of the 304 00:13:27,410 --> 00:13:29,690 item it needs to display in the position 305 00:13:29,690 --> 00:13:32,960 parameter - and that's this parameter here, 306 00:13:32,960 --> 00:13:34,430 Int, that's been passed to this function. 307 00:13:34,430 --> 00:13:36,980 So we retrieve the object at that 308 00:13:36,980 --> 00:13:37,610 position 309 00:13:37,610 --> 00:13:39,410 in our applications list, down here on 310 00:13:39,410 --> 00:13:43,820 line 29. Then we set the name and the 311 00:13:43,820 --> 00:13:46,100 artist and the summaries on line 31 through 312 00:13:46,100 --> 00:13:49,760 33, into the corresponding TextView. So 313 00:13:49,760 --> 00:13:50,930 once that's done, we're just returning 314 00:13:50,930 --> 00:13:53,060 the view on line 35, and that's actually 315 00:13:53,060 --> 00:13:55,640 our adapter finished. Now there are a 316 00:13:55,640 --> 00:13:57,200 couple of things that we should change, 317 00:13:57,200 --> 00:13:59,420 and we can see that Android Studio has 318 00:13:59,420 --> 00:14:00,920 flagged up some 319 00:14:00,920 --> 00:14:02,959 warnings on the right hand side, and I 320 00:14:02,959 --> 00:14:05,450 showed one of those on the screen. 321 00:14:05,450 --> 00:14:07,100 Now strangely, this version doesn't put a 322 00:14:07,100 --> 00:14:08,180 tick in the margin for our 323 00:14:08,180 --> 00:14:11,240 applications parameter. And you can see 324 00:14:11,240 --> 00:14:13,279 here that it does underline - you can see a 325 00:14:13,279 --> 00:14:14,870 little squiggle there - Property 326 00:14:14,870 --> 00:14:16,250 applications can be private. 327 00:14:16,250 --> 00:14:18,620 Now the resource can be private as well, 328 00:14:18,620 --> 00:14:21,320 so we're gonna change both of those, and 329 00:14:21,320 --> 00:14:22,339 that's going to make the line a little 330 00:14:22,339 --> 00:14:23,660 bit longer, so I'm going to split it up. So 331 00:14:23,660 --> 00:14:24,770 let's go ahead and do that, so we've got 332 00:14:24,770 --> 00:14:27,740 the Context, val. I'm going to change it 333 00:14:27,740 --> 00:14:28,910 before the val for the resource - I'm 334 00:14:28,910 --> 00:14:32,779 going to put private, and also put a 335 00:14:32,779 --> 00:14:35,630 private for the application as well, 336 00:14:35,630 --> 00:14:38,540 applications object. And let's put that 337 00:14:38,540 --> 00:14:41,180 on the next line, then I'm going to press 338 00:14:41,180 --> 00:14:42,470 ENTER there so we can see what we're 339 00:14:42,470 --> 00:14:43,880 doing a bit better there, and put another 340 00:14:43,880 --> 00:14:46,670 space there. The next warning we've got 341 00:14:46,670 --> 00:14:49,100 over here, is the fact that, or the class 342 00:14:49,100 --> 00:14:51,110 FeedAdapter's never used, but also the 343 00:14:51,110 --> 00:14:53,870 property TAG is never used. Well there's 344 00:14:53,870 --> 00:14:56,029 no logging at the moment - logging when 345 00:14:56,029 --> 00:14:57,320 these two functions are called will make 346 00:14:57,320 --> 00:14:58,760 it much easier to see what's going on, 347 00:14:58,760 --> 00:15:00,680 and so therefore, let's do that. So let's 348 00:15:00,680 --> 00:15:02,330 actually add some code for that, so 349 00:15:02,330 --> 00:15:06,050 firstly, for the getCount, we'll put a Log 350 00:15:06,050 --> 00:15:09,920 d -or Log.d, I should say - and it's gonna 351 00:15:09,920 --> 00:15:13,670 be TAG, and we'll put double quotes get 352 00:15:13,670 --> 00:15:19,779 Count called. And we'll also do the same 353 00:15:19,779 --> 00:15:22,310 for our getView, and I'll do that 354 00:15:22,310 --> 00:15:25,580 as the first line as well. And instead of 355 00:15:25,580 --> 00:15:26,959 getCount, obviously, it's gonna be getView 356 00:15:26,959 --> 00:15:29,270 called, and that obviously gets rid of 357 00:15:29,270 --> 00:15:30,589 one of the warnings now because TAG is 358 00:15:30,589 --> 00:15:33,680 being used. But that'll be enough to get it 359 00:15:33,680 --> 00:15:34,910 working now - we can look at some of 360 00:15:34,910 --> 00:15:37,220 those other warnings later. Let's 361 00:15:37,220 --> 00:15:39,920 actually see if our adapter works. So all 362 00:15:39,920 --> 00:15:41,180 we should have to do is change the 363 00:15:41,180 --> 00:15:43,490 adapter that we create in the onPost 364 00:15:43,490 --> 00:15:46,700 method of the DownloadData class, to use 365 00:15:46,700 --> 00:15:48,290 this new one. So let's go ahead 366 00:15:48,290 --> 00:15:52,490 and do that. So back in MainActivity, in 367 00:15:52,490 --> 00:15:54,770 our DownloadData onPostExecute, 368 00:15:54,770 --> 00:15:58,279 we've got val parseApplications. Then 369 00:15:58,279 --> 00:15:59,870 we've got our, moving on down, we've got 370 00:15:59,870 --> 00:16:01,970 our arrayAdapter code here. So what I'm 371 00:16:01,970 --> 00:16:03,500 going to do is comment out these two 372 00:16:03,500 --> 00:16:09,770 lines, because that's our old 373 00:16:09,770 --> 00:16:11,360 adapter, and we're going to use a new one. So 374 00:16:11,360 --> 00:16:16,100 I'm going to type val feedAdapter 375 00:16:16,100 --> 00:16:21,560 is equal to FeedAdapter, and we need to 376 00:16:21,560 --> 00:16:22,790 pass some arguments. The first one's 377 00:16:22,790 --> 00:16:26,149 going to be propContext. Then we need 378 00:16:26,149 --> 00:16:30,500 R.layout dot - this time it's list underscore 379 00:16:30,500 --> 00:16:33,050 record, and then we need parse 380 00:16:33,050 --> 00:16:37,970 Applications.applications, which is 381 00:16:37,970 --> 00:16:40,670 our list of FeedEntry objects. Then we 382 00:16:40,670 --> 00:16:45,250 need propListView.adapter 383 00:16:45,250 --> 00:16:49,519 equals feedAdapter, this time. Alright, 384 00:16:49,519 --> 00:16:51,019 so let's actually try running that to 385 00:16:51,019 --> 00:17:01,420 see that it works. 386 00:17:01,420 --> 00:17:02,980 Alright, so there's our app running and 387 00:17:02,980 --> 00:17:04,359 you can see that it's looking a lot more 388 00:17:04,359 --> 00:17:05,920 impressive now, than what it did look 389 00:17:05,920 --> 00:17:07,690 like before, and obviously, we can scroll 390 00:17:07,690 --> 00:17:09,910 that up and down. But what I'll do, this 391 00:17:09,910 --> 00:17:11,230 video's got quite long. So I'm going to 392 00:17:11,230 --> 00:17:13,359 stop the video here, and in the next one, 393 00:17:13,359 --> 00:17:14,470 what we'll do is we'll look at making 394 00:17:14,470 --> 00:17:17,349 our FeedAdapter more efficient. See you 395 00:17:17,349 --> 00:17:19,980 in the next video.