1 00:00:00,000 --> 00:00:04,400 [MUSIC] 2 00:00:04,400 --> 00:00:08,066 We left off with a simple load page method that gets called when our activity 3 00:00:08,066 --> 00:00:09,008 is first created. 4 00:00:09,008 --> 00:00:12,030 And as of right now, simply loads the first page of the story, 5 00:00:12,030 --> 00:00:13,146 which is at page zero. 6 00:00:13,146 --> 00:00:16,487 Now we want to change this to load a new page of the story based on whatever 7 00:00:16,487 --> 00:00:18,590 the user taps on as one of the choices. 8 00:00:18,590 --> 00:00:21,480 So, to do that, we need to add unclick listeners to our buttons and 9 00:00:21,480 --> 00:00:24,280 call this loadPage method when a button is tapped. 10 00:00:24,280 --> 00:00:27,645 That will cause all these views to be repopulated with fresh page data, 11 00:00:27,645 --> 00:00:29,720 were ever leaving the activity. 12 00:00:29,720 --> 00:00:32,120 We're just updating all the views inside it. 13 00:00:32,120 --> 00:00:35,260 So let's add the new OnClickListeners down here where we're setting the text 14 00:00:35,260 --> 00:00:36,310 for the buttons. 15 00:00:36,310 --> 00:00:39,523 I'm going to keep the choice one code together so, 16 00:00:39,523 --> 00:00:44,983 I'll add a few lines between here and then type choice1Button.setOnClickListener 17 00:00:44,983 --> 00:00:50,315 new OnClickListener, hit Enter and there we go, we have the onClick method. 18 00:00:50,315 --> 00:00:53,935 In here, the first thing we need is the index of the new page we want to load. 19 00:00:53,935 --> 00:00:58,728 So int nextPage =, and then from the page story we can getChoice1 20 00:00:58,728 --> 00:01:02,850 because we're in Choice1 button and get the NextPage. 21 00:01:05,719 --> 00:01:10,103 Okay, I was actually expecting to see an error here about page not being final. 22 00:01:10,103 --> 00:01:14,359 It looks like Android Studio might have automatically added the final keyword to 23 00:01:14,359 --> 00:01:18,426 our page variable to make sure that we can access it down here in this anonymous 24 00:01:18,426 --> 00:01:19,191 inner class. 25 00:01:19,191 --> 00:01:22,789 We have to remember that this anonymous inner class this onClickListener is 26 00:01:22,789 --> 00:01:24,082 a self-contained unit and 27 00:01:24,082 --> 00:01:28,026 it can't reference anything from outside of it unless we make that kind of change. 28 00:01:28,026 --> 00:01:32,589 All right, so now we can simply load this nextPage by calling, loadPage and 29 00:01:32,589 --> 00:01:33,960 passing in nextPage. 30 00:01:35,110 --> 00:01:38,070 Now we wanna do the exact same thing for choice two. 31 00:01:38,070 --> 00:01:40,310 Let's cheat and do a quick copy paste. 32 00:01:40,310 --> 00:01:44,330 As usual, I want to warn you to be very careful when copying and pasting code. 33 00:01:44,330 --> 00:01:46,265 It's very easy to make a copy and paste errors. 34 00:01:48,158 --> 00:01:51,833 Okay, so we want to change this to Choice2Button as well and 35 00:01:51,833 --> 00:01:55,869 then we want to change down here instead of getting from Choice1, 36 00:01:55,869 --> 00:01:58,336 let's get the next page from Choice2. 37 00:01:58,336 --> 00:01:59,222 Okay, we should be set. 38 00:01:59,222 --> 00:02:02,853 Let's run this to make sure that it's working as we expect it to. 39 00:02:02,853 --> 00:02:07,209 All right, I'm going to go back to the Pixel, Use that for future launches and 40 00:02:07,209 --> 00:02:07,810 click OK. 41 00:02:09,270 --> 00:02:09,950 Okay, so this time, 42 00:02:09,950 --> 00:02:14,240 I'm going to type in a different name, let's use Pasan, START YOUR ADVENTURE. 43 00:02:14,240 --> 00:02:16,990 And once again, we see the name being plugged in. 44 00:02:16,990 --> 00:02:20,980 And now, let's try the first choice, STOP AND INVESTIGATE. 45 00:02:20,980 --> 00:02:23,120 Okay, cool, look at that, we went to a new page. 46 00:02:23,120 --> 00:02:25,970 And, let's try the second choice too, EXPLORE THE ROVER. 47 00:02:27,050 --> 00:02:28,010 All right, look at this. 48 00:02:28,010 --> 00:02:29,450 We're working through the story. 49 00:02:29,450 --> 00:02:30,835 Let's EXPLORE THE COORDINATES. 50 00:02:30,835 --> 00:02:33,840 Uh-oh, we've run into an error. 51 00:02:33,840 --> 00:02:35,190 All right, so what's going on here? 52 00:02:35,190 --> 00:02:36,090 Here's a challenge. 53 00:02:36,090 --> 00:02:38,000 See if you can figure out what the error is, and 54 00:02:38,000 --> 00:02:40,070 then, I'll show you how we're going to fix it in the next video.