1 00:00:00,390 --> 00:00:05,070 We just left off with a lot of code that was generated by auto complete. 2 00:00:05,070 --> 00:00:08,480 We use on click listeners like this a lot in Android. 3 00:00:08,480 --> 00:00:10,720 So it'll make more and more sense the more you use it. 4 00:00:11,760 --> 00:00:14,110 This on click method, 5 00:00:14,110 --> 00:00:18,250 will run when ever this listener detects a click on our button. 6 00:00:18,250 --> 00:00:21,730 Just like opening our app triggers the onCreate method, 7 00:00:21,730 --> 00:00:24,900 typing on our button will trigger this onClick method. 8 00:00:24,900 --> 00:00:26,910 So anytime we click on our button, 9 00:00:26,910 --> 00:00:30,040 the code that we write inside these curly brackets will run. 10 00:00:31,160 --> 00:00:34,624 Let's add a comment in the onClick method to describe what we'd like to do. 11 00:00:34,624 --> 00:00:38,123 The button was clicked, 12 00:00:38,123 --> 00:00:43,060 so update the fact TextView with a new fact. 13 00:00:44,410 --> 00:00:47,040 All right, now we need a new fact. 14 00:00:47,040 --> 00:00:52,090 On the line below our comment, let's create a new string variable named fact. 15 00:00:52,090 --> 00:00:56,230 And let's set it equal to in quotation marks Ostriches 16 00:00:57,320 --> 00:00:59,620 can run faster than horses. 17 00:01:01,370 --> 00:01:03,210 And don't forget the semicolon. 18 00:01:03,210 --> 00:01:07,130 Now we need to update our text view to show this new fact. 19 00:01:07,130 --> 00:01:09,240 Remember when we were editing the layout? 20 00:01:09,240 --> 00:01:13,640 We can change the text of a text view by editing it's text property or 21 00:01:13,640 --> 00:01:17,150 by changing it directly in the layout's XML file. 22 00:01:17,150 --> 00:01:21,080 Android also allows us to make these kinds of changes in code. 23 00:01:21,080 --> 00:01:29,250 On a new line type factTextView.setText and then hit Enter to autocomplete. 24 00:01:30,560 --> 00:01:33,860 Notice that there's a list of different parameters down here. 25 00:01:33,860 --> 00:01:38,550 This is because there are different versions of this set text method. 26 00:01:38,550 --> 00:01:40,510 Each taken different parameters. 27 00:01:40,510 --> 00:01:44,780 We want this first one because it only has one parameter for the text. 28 00:01:44,780 --> 00:01:47,520 Now the data type here, CharSequence, 29 00:01:47,520 --> 00:01:51,240 might be a little confusing since we're using a String. 30 00:01:51,240 --> 00:01:54,650 But a String is just a sequence of characters, so 31 00:01:54,650 --> 00:02:00,350 it shouldn't be too surprising that all Strings are also CharSequences. 32 00:02:00,350 --> 00:02:06,360 Kind of like how text views are also views or how dogs are also animals. 33 00:02:06,360 --> 00:02:07,130 In Android, 34 00:02:07,130 --> 00:02:11,100 whenever you see a Charsequence, you can just pass in a string. 35 00:02:11,100 --> 00:02:16,390 All right, let's type fact in between the parenthesis to pass in our fact variable 36 00:02:16,390 --> 00:02:18,830 and now we are ready for the moment of truth. 37 00:02:18,830 --> 00:02:22,201 Let's click on the Run button, or hit Ctrl + Alt on Mac, 38 00:02:22,201 --> 00:02:24,742 or Shift + F10 on Windows to run our app. 39 00:02:27,951 --> 00:02:29,120 Looks good. 40 00:02:29,120 --> 00:02:30,700 Let's click on the button to test it. 41 00:02:32,818 --> 00:02:36,390 Did you know that ostriches can run faster than horses?