1 00:00:04,730 --> 00:00:08,780 So I ended the last video by asking the 2 00:00:08,780 --> 00:00:10,039 question, does it work? 3 00:00:10,039 --> 00:00:11,330 So let's actually try running this 4 00:00:11,330 --> 00:00:13,400 program to make sure that it does work. 5 00:00:13,400 --> 00:00:15,099 So we're going to run it on our emulator. 6 00:00:15,099 --> 00:00:17,180 Now we're going to go over here and click 7 00:00:17,180 --> 00:00:19,550 on this little green arrow on the 8 00:00:19,550 --> 00:00:21,710 toolbar, to run the app, then I'm going to 9 00:00:21,710 --> 00:00:23,630 choose the emulator. Now I've probably 10 00:00:23,630 --> 00:00:25,309 got a lot more emulators than you've 11 00:00:25,309 --> 00:00:27,079 actually got in your system, and you can 12 00:00:27,079 --> 00:00:28,009 actually see that some of these are 13 00:00:28,009 --> 00:00:29,899 missing a system image, but the one that I've 14 00:00:29,899 --> 00:00:32,180 got connected and currently using is 15 00:00:32,180 --> 00:00:35,420 this nexus 4 API 26, which of course is 16 00:00:35,420 --> 00:00:37,760 Android 8. So you want to select your 17 00:00:37,760 --> 00:00:41,540 Android 8 device, your emulator, and I'm 18 00:00:41,540 --> 00:00:42,590 doing that now, I'm going to click on 19 00:00:42,590 --> 00:00:43,390 OK. 20 00:00:43,390 --> 00:00:45,410 And I've already got it started so I'm 21 00:00:45,410 --> 00:00:47,420 going to come over here, and we'll have a 22 00:00:47,420 --> 00:00:49,400 look at what the app looks like on that 23 00:00:49,400 --> 00:00:51,560 device. You can see down the bottom of 24 00:00:51,560 --> 00:00:53,180 the screen there, that Gradle build is 25 00:00:53,180 --> 00:00:55,520 running, and we've got a progress bar 26 00:00:55,520 --> 00:00:57,440 that hasn't updated, but it is actually 27 00:00:57,440 --> 00:00:59,239 processing away for the first time and 28 00:00:59,239 --> 00:01:01,310 generating the build, the Android 29 00:01:01,310 --> 00:01:02,899 application, and then sending it to the 30 00:01:02,899 --> 00:01:04,699 emulator so that we can actually see 31 00:01:04,699 --> 00:01:06,590 what it looks like. And keep in mind that 32 00:01:06,590 --> 00:01:08,360 if you've got a slower computer and you're 33 00:01:08,360 --> 00:01:10,429 short of memory, it's definitely worth 34 00:01:10,429 --> 00:01:12,170 starting the emulator before you start 35 00:01:12,170 --> 00:01:13,880 coding, so it's up and running and ready 36 00:01:13,880 --> 00:01:15,469 for when you want to test your app. And 37 00:01:15,469 --> 00:01:17,179 you can see that, in my case, I had the 38 00:01:17,179 --> 00:01:21,560 emulator already running. 39 00:01:21,560 --> 00:01:24,360 Okay, so you can see the app is now 40 00:01:24,360 --> 00:01:26,369 on screen, and there's a couple of things 41 00:01:26,369 --> 00:01:27,960 I should explain about it in case you 42 00:01:27,960 --> 00:01:29,939 think that you messed up creating the 43 00:01:29,939 --> 00:01:32,220 layout in the challenge. Firstly though, 44 00:01:32,220 --> 00:01:34,080 let's test it, and when I click the 45 00:01:34,080 --> 00:01:35,580 button the message is added, or should be 46 00:01:35,580 --> 00:01:38,070 added, to the textView down here. So I've got 47 00:01:38,070 --> 00:01:39,930 the name there, if I just put in my 48 00:01:39,930 --> 00:01:42,080 name, 49 00:01:42,080 --> 00:01:45,539 and then click on button, you can see the 50 00:01:45,539 --> 00:01:48,180 button got tapped one time. And if we 51 00:01:48,180 --> 00:01:51,119 click it again, the button got tapped two 52 00:01:51,119 --> 00:01:53,789 time, and then one more time, you can see 53 00:01:53,789 --> 00:01:55,140 that the text this time is the button 54 00:01:55,140 --> 00:01:58,590 got tapped three time. So the actual 55 00:01:58,590 --> 00:02:00,299 concept is working well. The text is 56 00:02:00,299 --> 00:02:02,250 being added to the textView successfully. 57 00:02:02,250 --> 00:02:04,619 What we should have done is cleared the 58 00:02:04,619 --> 00:02:06,750 original text first, so we're going to do 59 00:02:06,750 --> 00:02:08,818 that when we go back to the code. I'm 60 00:02:08,818 --> 00:02:11,068 going to click just a few more times, to 61 00:02:11,068 --> 00:02:12,750 see what happens once we get to the 62 00:02:12,750 --> 00:02:15,660 stage of filling things up, and I'm 63 00:02:15,660 --> 00:02:19,110 tapping, and you can see now, or rather you 64 00:02:19,110 --> 00:02:20,190 can't see what's happening and that's 65 00:02:20,190 --> 00:02:21,330 because the text is now 66 00:02:21,330 --> 00:02:23,580 disappearing behind the on-screen 67 00:02:23,580 --> 00:02:26,010 keyboard. Now that's the first thing you 68 00:02:26,010 --> 00:02:28,140 might think you've got wrong, but it's 69 00:02:28,140 --> 00:02:30,269 okay and that's actually normal behavior 70 00:02:30,269 --> 00:02:32,910 on Android. Now the Plain Text widget 71 00:02:32,910 --> 00:02:34,739 that we used when working in the 72 00:02:34,739 --> 00:02:37,590 designer is an editText, and what an 73 00:02:37,590 --> 00:02:39,810 editText is, is basically a TextView 74 00:02:39,810 --> 00:02:41,940 that's been extended to allow editing. 75 00:02:41,940 --> 00:02:44,489 Now obviously, on an Android device you'd 76 00:02:44,489 --> 00:02:46,769 normally need the keyboard when typing, 77 00:02:46,769 --> 00:02:48,720 so the editText widget has been 78 00:02:48,720 --> 00:02:50,820 designed to cope when the keyboard's on 79 00:02:50,820 --> 00:02:53,220 the screen. Now because you can't type 80 00:02:53,220 --> 00:02:55,290 into a TextView, it doesn't havee that 81 00:02:55,290 --> 00:02:57,209 behavior. So there's nothing wrong with 82 00:02:57,209 --> 00:02:59,250 the layout as such - it's working as it 83 00:02:59,250 --> 00:03:01,560 should. Now if you did want the TextView 84 00:03:01,560 --> 00:03:03,510 to shrink to accommodate the keyboard, 85 00:03:03,510 --> 00:03:05,880 you could do that in your code, although, 86 00:03:05,880 --> 00:03:07,560 it may well be easier to use an edit 87 00:03:07,560 --> 00:03:10,109 Text, then disable it so that text can't be 88 00:03:10,109 --> 00:03:12,060 typed. That way you get the benefit of 89 00:03:12,060 --> 00:03:13,620 the added functionality an editText 90 00:03:13,620 --> 00:03:16,019 has, for dealing with the keyboard, while 91 00:03:16,019 --> 00:03:17,609 still having something that 92 00:03:17,609 --> 00:03:21,060 behaves more like a TextView. Now we'll 93 00:03:21,060 --> 00:03:22,739 be doing that in a later section just so 94 00:03:22,739 --> 00:03:25,260 you can see how it's done, but the second 95 00:03:25,260 --> 00:03:27,480 thing I want to show you, is, if I now 96 00:03:27,480 --> 00:03:29,280 dismiss the keyboard by clicking on this 97 00:03:29,280 --> 00:03:31,709 down arrow and I'll tap a few more times, 98 00:03:31,709 --> 00:03:33,450 or rather, because I'm running an 99 00:03:33,450 --> 00:03:36,050 emulator I'm using my mouse. 100 00:03:36,050 --> 00:03:38,010 Right til we get to the bottom of the 101 00:03:38,010 --> 00:03:42,599 screen on my emulator, and I'm still 102 00:03:42,599 --> 00:03:44,130 tapping now but you notice that 103 00:03:44,130 --> 00:03:47,040 the TextView doesn't scroll. So once 104 00:03:47,040 --> 00:03:48,420 again you haven't done anything wrong in 105 00:03:48,420 --> 00:03:50,700 your layout. The multi-line editText 106 00:03:50,700 --> 00:03:52,200 widget Scrolls when you set the 107 00:03:52,200 --> 00:03:54,510 scrollbar, but to make a TextView scroll, 108 00:03:54,510 --> 00:03:56,370 there's an extra step we need to do in 109 00:03:56,370 --> 00:03:59,040 the code. Now the final thing that needs 110 00:03:59,040 --> 00:04:00,750 to be fixed is that the message itself 111 00:04:00,750 --> 00:04:03,269 isn't very good. The button got tapped two 112 00:04:03,269 --> 00:04:06,150 time, got tapped three time, etc. well 113 00:04:06,150 --> 00:04:08,580 that isn't very good English. So overall, 114 00:04:08,580 --> 00:04:09,780 though, the program seems to be working 115 00:04:09,780 --> 00:04:12,239 fine so far, and we've successfully 116 00:04:12,239 --> 00:04:14,610 linked code to a button so that it 117 00:04:14,610 --> 00:04:16,560 responds to clicks and that it actually 118 00:04:16,560 --> 00:04:17,250 does something. 119 00:04:17,250 --> 00:04:19,260 But let's fix those three issues, though, 120 00:04:19,260 --> 00:04:21,029 that we've talked about and we'll do 121 00:04:21,029 --> 00:04:23,460 that by going back to the code. Now 122 00:04:23,460 --> 00:04:25,470 firstly, clearing the existing text from 123 00:04:25,470 --> 00:04:27,210 the TextView when the program starts is 124 00:04:27,210 --> 00:04:29,790 really easy, but before you switch to the 125 00:04:29,790 --> 00:04:31,889 layout to delete the text property, I'm 126 00:04:31,889 --> 00:04:33,290 going to show you another way. So 127 00:04:33,290 --> 00:04:35,790 clearing it in the layout is a perfectly 128 00:04:35,790 --> 00:04:37,440 good way to do it, by the way, but 129 00:04:37,440 --> 00:04:39,419 essentially, when you're starting out it 130 00:04:39,419 --> 00:04:41,130 can be very useful to leave text in the 131 00:04:41,130 --> 00:04:43,320 TextView widgets, as otherwise it can be 132 00:04:43,320 --> 00:04:45,120 really hard to tell that they're there 133 00:04:45,120 --> 00:04:47,130 without looking at the blueprint or 134 00:04:47,130 --> 00:04:49,020 selecting them. I'm going to show you a 135 00:04:49,020 --> 00:04:51,240 way around that later, but another way to 136 00:04:51,240 --> 00:04:53,190 clear it is to set its text property in 137 00:04:53,190 --> 00:04:55,919 code and provide an empty string. So what 138 00:04:55,919 --> 00:04:57,570 I'm going to do is add a few lines of 139 00:04:57,570 --> 00:04:59,940 code now. We're going to just scroll up 140 00:04:59,940 --> 00:05:03,270 here to the original definitions of the, 141 00:05:03,270 --> 00:05:04,350 well actually, we've got our original 142 00:05:04,350 --> 00:05:06,600 declarations up here, but then when we've 143 00:05:06,600 --> 00:05:09,150 added our findViewById calls for each 144 00:05:09,150 --> 00:05:11,850 below that TextView, we were going to 145 00:05:11,850 --> 00:05:13,169 initialize it. So we're going to put text 146 00:05:13,169 --> 00:05:18,479 View?.text = 147 00:05:18,479 --> 00:05:22,289 and two double quotes. Now unlike append, 148 00:05:22,289 --> 00:05:24,330 which adds text to any already 149 00:05:24,330 --> 00:05:26,370 there, setting the text property 150 00:05:26,370 --> 00:05:28,200 replaces all the texts in the TextView 151 00:05:28,200 --> 00:05:31,260 with the new text. By providing a blank 152 00:05:31,260 --> 00:05:33,120 string, which we've done here on line 23, 153 00:05:33,120 --> 00:05:35,460 that's two sets of speech marks with 154 00:05:35,460 --> 00:05:37,020 nothing between them, two double quotes 155 00:05:37,020 --> 00:05:39,330 in other words, we replace any existing 156 00:05:39,330 --> 00:05:41,160 text with nothing and that effectively 157 00:05:41,160 --> 00:05:42,780 clears what's already there on screen. 158 00:05:42,780 --> 00:05:45,419 Alright, the next thing to do is to add 159 00:05:45,419 --> 00:05:48,390 an s after the word time if the button's 160 00:05:48,390 --> 00:05:48,940 been clicked 161 00:05:48,940 --> 00:05:50,440 more than once, so that the English is 162 00:05:50,440 --> 00:05:53,080 correct. And what we can do is add the 163 00:05:53,080 --> 00:05:54,460 code for that. I'm going to start by 164 00:05:54,460 --> 00:05:57,100 adding some code to line 29. So what I'm 165 00:05:57,100 --> 00:05:58,810 going to do is put an if clause in there, 166 00:05:58,810 --> 00:06:03,780 so if parentheses numTimesClicked, 167 00:06:03,780 --> 00:06:06,970 if that is not equal to, so exclamation 168 00:06:06,970 --> 00:06:12,130 mark equal one and curly braces. Then 169 00:06:12,130 --> 00:06:15,280 we're going to put textView? 170 00:06:15,280 --> 00:06:19,000 dot append and parentheses, then in double 171 00:06:19,000 --> 00:06:20,970 quotes yes. 172 00:06:20,970 --> 00:06:23,470 So rather than checking for a number of 173 00:06:23,470 --> 00:06:25,360 clicks being greater than one, I've 174 00:06:25,360 --> 00:06:27,910 checked it for not equal to one. That way, 175 00:06:27,910 --> 00:06:29,680 if we ever change it to record the zero 176 00:06:29,680 --> 00:06:31,390 before the button's clicked, it would 177 00:06:31,390 --> 00:06:33,040 still read correctly, and that's because in 178 00:06:33,040 --> 00:06:35,320 English you'd say zero times and not 179 00:06:35,320 --> 00:06:37,720 zero time. Now that's not true in all 180 00:06:37,720 --> 00:06:39,970 languages though. In fact, Android has 181 00:06:39,970 --> 00:06:41,260 full support for dealing with 182 00:06:41,260 --> 00:06:43,120 translations into other languages, 183 00:06:43,120 --> 00:06:45,190 including the different way of phrasing 184 00:06:45,190 --> 00:06:47,230 things when there are zero, one or more , 185 185 00:06:47,230 --> 00:06:49,060 than one of them. So it's a good idea to 186 00:06:49,060 --> 00:06:51,040 design programs with international users 187 00:06:51,040 --> 00:06:52,990 in mind. Now I'm not going to do that 188 00:06:52,990 --> 00:06:54,820 right now, though, because we've already 189 00:06:54,820 --> 00:06:56,169 got enough to think about at the moment. 190 00:06:56,169 --> 00:06:58,120 But we will be coming back to this 191 00:06:58,120 --> 00:06:59,919 because it's one of the reasons for some 192 00:06:59,919 --> 00:07:01,360 of the warnings we didn't resolve in the 193 00:07:01,360 --> 00:07:03,610 layout designer. Alright, so at this 194 00:07:03,610 --> 00:07:05,290 point that's two of our problems sorted. 195 00:07:05,290 --> 00:07:07,360 There's just the scrolling to handle now. 196 00:07:07,360 --> 00:07:09,430 Now I mentioned that the TextView 197 00:07:09,430 --> 00:07:11,530 doesn't automatically enable scrolling, 198 00:07:11,530 --> 00:07:13,630 just because we turned on the scroll bar, 199 00:07:13,630 --> 00:07:17,110 but the editText widget does. In fact, 200 00:07:17,110 --> 00:07:18,730 the editText just does what we're 201 00:07:18,730 --> 00:07:20,860 about to do, automatically when scroll 202 00:07:20,860 --> 00:07:22,480 bars are enabled, and that's one of the 203 00:07:22,480 --> 00:07:24,490 ways that it extends the TextView. So 204 00:07:24,490 --> 00:07:25,419 what we're going to do, though, is we're 205 00:07:25,419 --> 00:07:27,280 going to add some code back up here, onto 206 00:07:27,280 --> 00:07:31,240 line that 24, and this is just going to 207 00:07:31,240 --> 00:07:33,160 make the TextView scroll. So we're going 208 00:07:33,160 --> 00:07:38,410 to type textView?. and 209 00:07:38,410 --> 00:07:40,240 select movementMethod, as you can see 210 00:07:40,240 --> 00:07:42,970 there, equals and then we're going to 211 00:07:42,970 --> 00:07:46,150 type scroll, or Scrolling, I should say, 212 00:07:46,150 --> 00:07:49,690 MovementMethod and parentheses on the 213 00:07:49,690 --> 00:07:52,120 end. Now assigning a new 214 00:07:52,120 --> 00:07:53,919 ScrollingMovementMethod to the text 215 00:07:53,919 --> 00:07:55,930 Views movementMethod property, is all 216 00:07:55,930 --> 00:07:57,760 that's needed to make the TextView 217 00:07:57,760 --> 00:08:00,160 scroll. Now this only works because we 218 00:08:00,160 --> 00:08:02,200 added a vertical scrollbar in the layout, 219 00:08:02,200 --> 00:08:05,080 so that step was still needed. Al 220 00:08:05,080 --> 00:08:06,850 right, so at this point now, it's time to 221 00:08:06,850 --> 00:08:08,980 test the program again, just to make sure 222 00:08:08,980 --> 00:08:10,390 that we've hopefully ironed out all these 223 00:08:10,390 --> 00:08:13,240 problems. Now the emulator was running 224 00:08:13,240 --> 00:08:15,130 before but this time, now that we've got 225 00:08:15,130 --> 00:08:17,500 a deployed version of the program, the 226 00:08:17,500 --> 00:08:19,120 instant run should automatically update 227 00:08:19,120 --> 00:08:20,740 the app for us on the virtual device and 228 00:08:20,740 --> 00:08:23,110 restart the app for us fairly quickly. So 229 00:08:23,110 --> 00:08:25,060 I'm going to run that and then tab over 230 00:08:25,060 --> 00:08:26,260 to our emulator. 231 00:08:26,260 --> 00:08:28,090 We should find it's a lot faster to 232 00:08:28,090 --> 00:08:32,559 start this time. Alright, so there's our 233 00:08:32,559 --> 00:08:35,080 app again. Now firstly, notice that we're 234 00:08:35,080 --> 00:08:37,210 starting with a clear area now, so 235 00:08:37,210 --> 00:08:40,179 clearly the dot text setting that to 236 00:08:40,179 --> 00:08:43,030 an empty string worked. I'm going to click the 237 00:08:43,030 --> 00:08:45,190 button a few times - the button got tapped 238 00:08:45,190 --> 00:08:47,620 one time - and notice we've now 239 00:08:47,620 --> 00:08:49,900 got the correct s being added on the end, 240 00:08:49,900 --> 00:08:52,420 two times, and tap it a few more times, 241 00:08:52,420 --> 00:08:55,380 and now if I dismiss the keyboard, and 242 00:08:55,380 --> 00:08:58,120 let's see what happens if we get down to 243 00:08:58,120 --> 00:08:59,410 the bottom, will that actually scroll for 244 00:08:59,410 --> 00:09:03,820 us. And you can see that's still not 245 00:09:03,820 --> 00:09:06,970 scrolling at this point for us. However, 246 00:09:06,970 --> 00:09:10,480 we can scroll it, as you can see here, and 247 00:09:10,480 --> 00:09:12,010 see the rest of the text by scrolling it 248 00:09:12,010 --> 00:09:14,980 up and down. It disappears if we haven't 249 00:09:14,980 --> 00:09:16,480 selected it, in other words, if you didn't 250 00:09:16,480 --> 00:09:19,030 have a finger and moving it up and down. 251 00:09:19,030 --> 00:09:20,950 If you're using a real device, or in my case, 252 00:09:20,950 --> 00:09:22,750 I'm using the mouse, we can see that it 253 00:09:22,750 --> 00:09:25,510 does now scroll for us. Keep in mind, 254 00:09:25,510 --> 00:09:26,830 though, that emulators are just that - 255 00:09:26,830 --> 00:09:28,930 emulators. They're not real devices and 256 00:09:28,930 --> 00:09:30,970 it's rare to control a real Android 257 00:09:30,970 --> 00:09:32,740 device with a mouse. It is possible, but 258 00:09:32,740 --> 00:09:34,810 of course, most people won't do that, 259 00:09:34,810 --> 00:09:36,760 so the mouse here is behaving like a 260 00:09:36,760 --> 00:09:40,240 finger on the phone's screen. And again, 261 00:09:40,240 --> 00:09:41,650 I'm mentioning that because the scroll 262 00:09:41,650 --> 00:09:43,480 indicator, as you can see, clearly doesn't 263 00:09:43,480 --> 00:09:45,460 appear until I click and hold down the 264 00:09:45,460 --> 00:09:47,290 mouse button on the TextView. When I did 265 00:09:47,290 --> 00:09:49,330 that we were able to then scroll up or 266 00:09:49,330 --> 00:09:51,370 down, depending on where we are on the 267 00:09:51,370 --> 00:09:53,920 screen. And the other thing I want to point 268 00:09:53,920 --> 00:09:55,990 out here is that what we can see on the 269 00:09:55,990 --> 00:09:57,040 right hand side, that's a scroll 270 00:09:57,040 --> 00:09:59,950 indicator, not a scroll bar. On your 271 00:09:59,950 --> 00:10:02,110 operating system, Windows, Mac or Linux, you 272 00:10:02,110 --> 00:10:04,360 scroll by dragging the scroll bars. but 273 00:10:04,360 --> 00:10:06,190 on Android you scroll by dragging the 274 00:10:06,190 --> 00:10:08,200 screen. So keeping the mouse button down 275 00:10:08,200 --> 00:10:09,790 and moving up and down as I'm doing now, 276 00:10:09,790 --> 00:10:12,070 the contents of the TextView are 277 00:10:12,070 --> 00:10:14,530 scrolling, so that's how you'll do it. Al 278 00:10:14,530 --> 00:10:15,820 right, so I think overall that's looking 279 00:10:15,820 --> 00:10:15,970 a bit 280 00:10:15,970 --> 00:10:17,889 better. There's still a slight problem, 281 00:10:17,889 --> 00:10:19,750 though, and if we go back up to the top, 282 00:10:19,750 --> 00:10:21,310 you may have noticed it. We've still got 283 00:10:21,310 --> 00:10:23,500 this blank line up here. So it's putting a 284 00:10:23,500 --> 00:10:25,899 blank line before the first message, and 285 00:10:25,899 --> 00:10:27,490 actually i think that would make for a 286 00:10:27,490 --> 00:10:30,790 good challenge. Alright, so the challenge 287 00:10:30,790 --> 00:10:33,160 is to change the code so that a blank 288 00:10:33,160 --> 00:10:35,589 line isn't printed before the messages, 289 00:10:35,589 --> 00:10:39,129 but is printed after them. So that's your 290 00:10:39,129 --> 00:10:40,509 our challenge. I'm going to pause the 291 00:10:40,509 --> 00:10:42,279 video now. See how you go about making 292 00:10:42,279 --> 00:10:44,050 that change, and come back and you can 293 00:10:44,050 --> 00:10:46,300 actually see our solution. See you when 294 00:10:46,300 --> 00:10:50,259 you get back. Alright, so there's always 295 00:10:50,259 --> 00:10:52,389 more than one way to code things - even a 296 00:10:52,389 --> 00:10:54,639 simple change like this one. So the real 297 00:10:54,639 --> 00:10:56,110 test with all the challenges in the 298 00:10:56,110 --> 00:10:59,199 course is, does it work? So if your 299 00:10:59,199 --> 00:11:00,939 messages print out fine, with each one on 300 00:11:00,939 --> 00:11:02,680 a new line and no blank line at the 301 00:11:02,680 --> 00:11:04,300 start, then you've completed the 302 00:11:04,300 --> 00:11:06,699 challenge. So my solution, wwll let's have a 303 00:11:06,699 --> 00:11:08,709 look at that. What I'm going to do is 304 00:11:08,709 --> 00:11:11,860 actually change the output. I'm going to 305 00:11:11,860 --> 00:11:14,949 get rid of the \n at the start of the 306 00:11:14,949 --> 00:11:17,800 string. What I'm going to do is make a 307 00:11:17,800 --> 00:11:20,170 change to add it at the end. I'm going to 308 00:11:20,170 --> 00:11:23,259 come down here to our if test. I'm 309 00:11:23,259 --> 00:11:25,899 going to add a \n there. Then 310 00:11:25,899 --> 00:11:27,100 what I'm going to do is change the code 311 00:11:27,100 --> 00:11:31,959 for an else, else textView? 312 00:11:31,959 --> 00:11:35,529 dot append double quotes and in 313 00:11:35,529 --> 00:11:38,410 parentheses, \n, and obviously, I 314 00:11:38,410 --> 00:11:40,449 removed the \n at the start as 315 00:11:40,449 --> 00:11:42,639 well. So we're consequently making sure 316 00:11:42,639 --> 00:11:45,610 there's the backslash n will appear on 317 00:11:45,610 --> 00:11:47,709 any text that, or at the end of the line of 318 00:11:47,709 --> 00:11:50,829 any text that is showing, or is being 319 00:11:50,829 --> 00:11:53,800 outputted onto the screen. Alright, so 320 00:11:53,800 --> 00:11:55,829 let's go ahead and run the program now, 321 00:11:55,829 --> 00:11:58,420 and check that the challenge 322 00:11:58,420 --> 00:12:03,399 does actually work. Alright, so we're 323 00:12:03,399 --> 00:12:05,160 going to just press the button, 324 00:12:05,160 --> 00:12:08,379 press the button a few more times, and you can 325 00:12:08,379 --> 00:12:09,610 see it seems to be working a lot better 326 00:12:09,610 --> 00:12:12,189 now. We've still got a bit of a gap there 327 00:12:12,189 --> 00:12:14,290 but that's just a normal gap spacing now, 328 00:12:14,290 --> 00:12:17,350 between controls, as opposed to the 329 00:12:17,350 --> 00:12:18,879 problem before. We had a much larger gap 330 00:12:18,879 --> 00:12:20,850 and that was caused by the initial 331 00:12:20,850 --> 00:12:22,990 backslash n that was at the start of the 332 00:12:22,990 --> 00:12:23,980 line, before we actually started 333 00:12:23,980 --> 00:12:24,500 outputting. 334 00:12:24,500 --> 00:12:27,110 So that's the challenge sorted out. There 335 00:12:27,110 --> 00:12:28,550 is still a problem, though, and I'm going 336 00:12:28,550 --> 00:12:30,020 to show you how to fix that in a later 337 00:12:30,020 --> 00:12:32,510 video. So what I'll do first is just make 338 00:12:32,510 --> 00:12:36,580 sure that we can still scroll these. 339 00:12:36,580 --> 00:12:38,570 You can still scroll it so that's still 340 00:12:38,570 --> 00:12:41,300 working as well. Alright, but again, I've 341 00:12:41,300 --> 00:12:42,290 mentioned that there's still a problem, 342 00:12:42,290 --> 00:12:44,000 though, and this problem I'm about to 343 00:12:44,000 --> 00:12:45,410 show you, I'm going to show you how to fix in 344 00:12:45,410 --> 00:12:47,960 a later video. Now remember that I said 345 00:12:47,960 --> 00:12:49,730 you should always test your code in both 346 00:12:49,730 --> 00:12:52,610 portrait and landscape. Now when I go 347 00:12:52,610 --> 00:12:55,670 ahead and rotate this, so rotate the 348 00:12:55,670 --> 00:12:57,260 emulator into landscape, you can see 349 00:12:57,260 --> 00:13:00,710 over here, I'm going to do that. You can 350 00:13:00,710 --> 00:13:02,240 see as soon as I did that, all the messages 351 00:13:02,240 --> 00:13:04,940 disappeared. And just to confirm that, if 352 00:13:04,940 --> 00:13:06,680 I add a few more now in landscape 353 00:13:06,680 --> 00:13:10,070 mode, again, I can still scroll as you can 354 00:13:10,070 --> 00:13:11,930 see there. But if I then just move this 355 00:13:11,930 --> 00:13:13,190 over so we can see it a bit better, and 356 00:13:13,190 --> 00:13:17,240 if I rotate back to portrait, you can see we've 357 00:13:17,240 --> 00:13:18,620 got the same problem - the messages are 358 00:13:18,620 --> 00:13:21,110 disappearing again. I'm going to show you 359 00:13:21,110 --> 00:13:22,850 how to deal with that in the next video. 360 00:13:22,850 --> 00:13:25,130 For now though, I'm going to tell you 361 00:13:25,130 --> 00:13:26,540 that the reason it happens is that 362 00:13:26,540 --> 00:13:29,030 Android destroys your activity when the 363 00:13:29,030 --> 00:13:31,880 device orientation changes, then creates 364 00:13:31,880 --> 00:13:34,760 it again in the new orientation. Now that 365 00:13:34,760 --> 00:13:36,320 might take a moment to sink in because 366 00:13:36,320 --> 00:13:38,150 it sounds like a very strange way to do 367 00:13:38,150 --> 00:13:38,480 things. 368 00:13:38,480 --> 00:13:40,430 Destroying the activity just because the 369 00:13:40,430 --> 00:13:42,790 user rotates a phone seems a bit drastic, 370 00:13:42,790 --> 00:13:45,350 but in fact, it's a very elegant solution 371 00:13:45,350 --> 00:13:47,930 to a problem that's more complex than it 372 00:13:47,930 --> 00:13:49,760 may appear to be. Now it's true that 373 00:13:49,760 --> 00:13:52,820 that is what Android does, and you 374 00:13:52,820 --> 00:13:54,230 know it works because you've rotated 375 00:13:54,230 --> 00:13:55,820 your phone loads of times and your apps 376 00:13:55,820 --> 00:13:57,290 have carried on with the new screen size 377 00:13:57,290 --> 00:13:59,750 with no problems. Now in the next video, 378 00:13:59,750 --> 00:14:01,430 we're going to start extending the app 379 00:14:01,430 --> 00:14:02,990 so it does something a bit more useful, 380 00:14:02,990 --> 00:14:04,670 and then we're going to look at how to cope 381 00:14:04,670 --> 00:14:06,830 with changes in orientation when your 382 00:14:06,830 --> 00:14:08,810 app is running. So I'll see you in the 383 00:14:08,810 --> 00:14:11,200 next video.