1 00:00:00,000 --> 00:00:04,060 [MUSIC] 2 00:00:04,060 --> 00:00:06,410 Welcome back. 3 00:00:06,410 --> 00:00:11,180 We've set up our user interface, the view portion of the MVC pattern. 4 00:00:11,180 --> 00:00:12,380 The model portion, 5 00:00:12,380 --> 00:00:17,230 our Hour class, will need a little more work down the road, but nothing too major. 6 00:00:18,240 --> 00:00:20,020 I wan to turn our attention, at least for 7 00:00:20,020 --> 00:00:23,730 a little bit here, to the controller portion of the MVC design pattern. 8 00:00:24,940 --> 00:00:28,313 I've mentioned adapter and view holders a couple of times now. 9 00:00:28,313 --> 00:00:30,810 But what are they exactly? 10 00:00:30,810 --> 00:00:32,320 And how do they all fit together? 11 00:00:33,540 --> 00:00:38,000 When we use a RecyclerView, there are a few bits and pieces we need. 12 00:00:38,000 --> 00:00:42,020 We have data, our array of hourly info for this project. 13 00:00:42,020 --> 00:00:44,480 And we have a RecyclerView. 14 00:00:44,480 --> 00:00:48,400 What we need to do to display the data in the RecyclerView? 15 00:00:48,400 --> 00:00:52,550 A common design pattern in Android is to use a special component 16 00:00:52,550 --> 00:00:56,150 called an adapter to, well, adapt data for the view. 17 00:00:57,220 --> 00:00:59,360 We set the data for the adapter and 18 00:00:59,360 --> 00:01:03,980 let the adapter do its magic to make the data look nice inside the RecyclerView. 19 00:01:05,160 --> 00:01:08,316 The other pieces to the puzzle are a LayoutManager, 20 00:01:08,316 --> 00:01:11,051 which manages the positioning of the items. 21 00:01:11,051 --> 00:01:14,246 And a ViewHolder, which as the name would indicate, 22 00:01:14,246 --> 00:01:18,060 holds the views we added to our list item layout. 23 00:01:18,060 --> 00:01:19,927 Our task then are to, first, 24 00:01:19,927 --> 00:01:24,430 create an Adapter to handle the data collection and bind it to the View. 25 00:01:25,630 --> 00:01:27,910 Create a ViewHolder inside the Adapter. 26 00:01:29,060 --> 00:01:31,810 Connect the Adapter to the Activity. 27 00:01:31,810 --> 00:01:35,080 And assign a LayoutManager to manage the item position. 28 00:01:36,430 --> 00:01:38,090 Something to note here. 29 00:01:38,090 --> 00:01:43,020 Since we're using the Android Data Binding Library, many of the data binding tasks 30 00:01:43,020 --> 00:01:47,280 that move data around the list and RecyclerView are handled for us. 31 00:01:47,280 --> 00:01:51,699 There are other ways outside the Data Binding Library to accomplish these tasks. 32 00:01:51,699 --> 00:01:55,621 And I've put links in the teacher's notes for further reading in case you come 33 00:01:55,621 --> 00:01:58,430 across a different method in your development career.