1 00:00:00,000 --> 00:00:04,968 [MUSIC] 2 00:00:04,968 --> 00:00:08,889 Originally in Android development, a ListView was the only option for 3 00:00:08,889 --> 00:00:11,730 showing items in a scrolling list. 4 00:00:11,730 --> 00:00:15,005 It provided a convenient way to display the list and 5 00:00:15,005 --> 00:00:18,165 offer some good functionality and conveniences. 6 00:00:18,165 --> 00:00:22,225 We were able to easily add things like on item click listeners and 7 00:00:22,225 --> 00:00:25,435 use default adapters with ListViews. 8 00:00:25,435 --> 00:00:29,875 Android 5.0, lollipop introduced the RecyclerView. 9 00:00:29,875 --> 00:00:33,325 And through the support library makes it compatible 10 00:00:33,325 --> 00:00:36,094 all the way back to Android API level 7. 11 00:00:37,370 --> 00:00:40,400 I've mentioned that we'll be using a RecyclerView to display our data, 12 00:00:41,670 --> 00:00:43,100 I'm all for recycling. 13 00:00:43,100 --> 00:00:45,610 Paper, cardboard, batteries, but 14 00:00:45,610 --> 00:00:49,340 what exactly is a RecyclerView when it comes to Android app? 15 00:00:49,340 --> 00:00:51,670 What are we gonna be recycling there? 16 00:00:51,670 --> 00:00:55,950 The RecyclerView widget is, according to the Android documentation, 17 00:00:55,950 --> 00:00:58,750 a more advanced and flexible version of ListView. 18 00:00:59,830 --> 00:01:03,300 In a nutshell, it is great for large sets of data and 19 00:01:03,300 --> 00:01:07,160 certain operations like animating items in a list. 20 00:01:07,160 --> 00:01:10,960 And as I mentioned, it's backwards compatible. 21 00:01:10,960 --> 00:01:16,070 It allows for the reuse or recycling of the ListItemView holder. 22 00:01:16,070 --> 00:01:20,680 When our list contains more information than we'll want to display at one time, 23 00:01:20,680 --> 00:01:23,900 Android takes a just in time approach. 24 00:01:23,900 --> 00:01:26,180 This means that Android creates the display for 25 00:01:26,180 --> 00:01:29,640 list items right when they are needed on the screen. 26 00:01:29,640 --> 00:01:32,880 Now there is still some overhead in creating views for the first time. 27 00:01:32,880 --> 00:01:37,520 So, to make this as smooth as possible, we can create one set of views for 28 00:01:37,520 --> 00:01:40,370 just the items that can fit on the screen. 29 00:01:40,370 --> 00:01:43,260 We can then reuse those containers over and 30 00:01:43,260 --> 00:01:48,050 over again as one item scrolls off or reclaim the view add object for it and 31 00:01:48,050 --> 00:01:53,020 fill it with new data from the next item that is about to scroll onto the screen. 32 00:01:54,220 --> 00:01:57,710 This saves room in memory and offers great performance improvements 33 00:01:57,710 --> 00:02:01,640 by recycling the container as it scrolls off the screen. 34 00:02:01,640 --> 00:02:05,830 Just the list of data is needed to maintained and bound to the view. 35 00:02:05,830 --> 00:02:10,790 At a high level using a RecyclerView has the following steps: first, 36 00:02:10,790 --> 00:02:14,260 we define a model class to be used as a data source. 37 00:02:14,260 --> 00:02:16,390 We've done this already with our hour class. 38 00:02:17,500 --> 00:02:20,470 Second, we add a RecyclerView to our activity. 39 00:02:21,630 --> 00:02:26,530 Next, we create a custom layout for the raw of data to be displayed. 40 00:02:26,530 --> 00:02:28,878 In our case it would be hourly weather data, 41 00:02:28,878 --> 00:02:33,650 with the hour, an icon, a summary and estimated temperature. 42 00:02:34,800 --> 00:02:40,290 Fourth, we need to create an adapter which we'll talk about more later in the course. 43 00:02:40,290 --> 00:02:44,480 Finally, we need to bind our data to our model to populate the RecyclerView. 44 00:02:45,600 --> 00:02:50,930 There are several steps to this and it can get pretty complicated rather quickly. 45 00:02:50,930 --> 00:02:54,230 Don't worry, we'll work through them one at a time, step by step. 46 00:02:55,230 --> 00:03:00,370 First, we'll create an hourly forecast activity to house a RecyclerView and 47 00:03:00,370 --> 00:03:03,300 build an adapter for it to display our data. 48 00:03:03,300 --> 00:03:05,250 We'll also need to set up a view holder and 49 00:03:05,250 --> 00:03:07,930 use the list item layout to handle the custom layout. 50 00:03:09,060 --> 00:03:12,700 I know it's a lot to cover, but once you have this project completed, 51 00:03:12,700 --> 00:03:16,820 you'll have a terrific sample to build from for your own future projects.