1 00:00:04,120 --> 00:00:09,650 G'day everyone. Welcome back. Our Settings Dialog will extend the appCompatDialog 2 00:00:09,650 --> 00:00:13,550 Fragment class. Create a new Kotlin class called 3 00:00:13,550 --> 00:00:31,700 SettingsDialog, and choose class before hitting OK. I'll add the usual log tag 4 00:00:31,700 --> 00:00:36,910 and extend the appCompatDialogFragment class. 5 00:00:48,440 --> 00:00:53,340 The first step is to inflate our layout in the onCreateView function. 6 00:00:53,340 --> 00:00:58,980 I'll get Android studio to generate the stub, then inflate our layout. I'll also log the 7 00:00:58,980 --> 00:01:01,910 function being called. 8 00:01:23,260 --> 00:01:29,200 Note that we're using onCreateView, rather than oncreateDialog. In the 9 00:01:29,200 --> 00:01:35,100 appDialog class we used a dialog builder in the onCreateDialog function. Here, we're 10 00:01:35,100 --> 00:01:39,800 inflating the view from a layout resource file in onCreateView. 11 00:01:39,800 --> 00:01:43,520 Be careful if you mix the two functions in the same class. You can get unexpected 12 00:01:43,530 --> 00:01:48,660 problems. We need to access the individual widgets, which is why we're 13 00:01:48,660 --> 00:01:55,170 inflating a view in onCreateView, rather than using a dialog builder. Alright, we 14 00:01:55,170 --> 00:01:59,010 want to set up the onClickListeners for our buttons, which we'll do in the 15 00:01:59,010 --> 00:02:02,790 onViewCreated function. I'll get Android Studio to generate that 16 00:02:02,790 --> 00:02:07,240 one as well, after onCreateView. 17 00:02:30,900 --> 00:02:36,700 I'll write the save values function later. If the user taps the OK button, we'll save 18 00:02:36,700 --> 00:02:41,709 the values and dismiss the dialogue. If they tap cancel, we'll just dismiss the 19 00:02:41,709 --> 00:02:47,060 dialogue. A dialog isn't going to do a lot at the moment but we can test it. 20 00:02:47,060 --> 00:02:54,900 Firstly, we add code in MainActivity, in the onOptionsItemDelected function. 21 00:02:59,189 --> 00:03:05,760 Uncomment this line and replace the true. 22 00:03:10,079 --> 00:03:19,150 Alright, we can run the app and test our settings dialog. When I choose settings 23 00:03:19,150 --> 00:03:27,069 from the menu, our dialog appears. The day that starts the week can be selected 24 00:03:27,069 --> 00:03:33,040 from the spinner widget, which drops down to show all the days we defined in the 25 00:03:33,040 --> 00:03:42,009 string array. I can also drag the seek-bar left and right, but we're not getting the 26 00:03:42,009 --> 00:03:47,019 value to show yet and nothing's being saved. But our basic settings dialog is 27 00:03:47,019 --> 00:03:50,379 working. We've still got a bit more work to do. 28 00:03:50,380 --> 00:03:56,880 It would look a lot better with a title too. I'll tap OK to dismiss the dialogue, 29 00:03:56,880 --> 00:03:59,700 and we'll continue with the code in the next video. 30 00:03:59,709 --> 00:04:02,669 I'll see you there.