1 00:00:04,710 --> 00:00:06,120 all right so let's see if our 2 00:00:06,120 --> 00:00:07,830 application works before we continue 3 00:00:07,830 --> 00:00:10,860 adding more code I'm just going to start 4 00:00:10,860 --> 00:00:16,230 my emulator and I'll just fast forward 5 00:00:16,230 --> 00:00:22,189 this until it's are loaded 6 00:00:22,189 --> 00:00:23,929 all right so emulator started so let's 7 00:00:23,929 --> 00:00:25,820 run the application and just test this 8 00:00:25,820 --> 00:00:32,238 out so want to make sure that all ten of 9 00:00:32,238 --> 00:00:34,100 the numeric buttons work and also the 10 00:00:34,100 --> 00:00:36,470 dock button and we're going to test it 11 00:00:36,470 --> 00:00:38,239 in landscape as well that's particularly 12 00:00:38,239 --> 00:00:40,100 important here because we're using a 13 00:00:40,100 --> 00:00:44,000 different layout for landscape all right 14 00:00:44,000 --> 00:00:46,699 so let's start there digits seven eight 15 00:00:46,699 --> 00:00:53,140 nine four five six one two three zero 16 00:00:53,140 --> 00:00:55,850 and click on the dot and I shouldn't be 17 00:00:55,850 --> 00:00:57,110 able to click on the dot again that's 18 00:00:57,110 --> 00:00:57,710 correct 19 00:00:57,710 --> 00:00:59,570 so all ten of the digit buttons work and 20 00:00:59,570 --> 00:01:01,009 the decimal point will only work once 21 00:01:01,009 --> 00:01:02,869 and the reason for that by the way is 22 00:01:02,869 --> 00:01:05,449 because we set the edit text to number 23 00:01:05,449 --> 00:01:07,580 decimal in the layout an android takes 24 00:01:07,580 --> 00:01:09,500 care of only allowing a single full stop 25 00:01:09,500 --> 00:01:11,330 to be entered which saves us from having 26 00:01:11,330 --> 00:01:12,830 to worry about checking the validity of 27 00:01:12,830 --> 00:01:14,720 the number that's entered now if your 28 00:01:14,720 --> 00:01:16,490 dot button doesn't work check the layout 29 00:01:16,490 --> 00:01:18,920 if you made the edit takes just a number 30 00:01:18,920 --> 00:01:20,570 signed in the layout then it won't 31 00:01:20,570 --> 00:01:21,979 accept the decimal point you need that 32 00:01:21,979 --> 00:01:24,079 number decimal as well alright so let's 33 00:01:24,079 --> 00:01:25,790 quickly check landscapes working as well 34 00:01:25,790 --> 00:01:28,969 so I'm going to just delete this delete 35 00:01:28,969 --> 00:01:31,179 those numbers again seven eight nine 36 00:01:31,179 --> 00:01:36,439 four five six one two three zero dot and 37 00:01:36,439 --> 00:01:38,630 I can't press the dock more than once so 38 00:01:38,630 --> 00:01:42,560 that's actually working well alright so 39 00:01:42,560 --> 00:01:45,020 let's go back to the code now there's 40 00:01:45,020 --> 00:01:46,429 still a bit of validation that we have 41 00:01:46,429 --> 00:01:47,689 to code but so we're going to come back 42 00:01:47,689 --> 00:01:49,700 to that later the moment though the 43 00:01:49,700 --> 00:01:51,590 buttons are doing something in our 44 00:01:51,590 --> 00:01:54,439 onclicklistener is working nicely so at 45 00:01:54,439 --> 00:01:56,630 this point is now time to create the own 46 00:01:56,630 --> 00:01:58,850 click listener for the operation buttons 47 00:01:58,850 --> 00:02:00,740 now once again we're going to be passing 48 00:02:00,740 --> 00:02:03,409 the actual view that causes the onclick 49 00:02:03,409 --> 00:02:05,810 to be called so we'll read its text to 50 00:02:05,810 --> 00:02:07,579 work out which operation it represents 51 00:02:07,579 --> 00:02:09,590 I'm going to type the code in first and 52 00:02:09,590 --> 00:02:11,380 then we'll go through this afterwards 53 00:02:11,380 --> 00:02:15,080 we're going to do that below our button 54 00:02:15,080 --> 00:02:18,050 code our set on click listeners for our 55 00:02:18,050 --> 00:02:21,910 button code so valves base open listener 56 00:02:21,910 --> 00:02:26,240 because view with a capital v dot on 57 00:02:26,240 --> 00:02:29,300 click listener then we've got a left or 58 00:02:29,300 --> 00:02:31,580 right curly braces and V dash greater 59 00:02:31,580 --> 00:02:33,890 than sign then it's going to talk about 60 00:02:33,890 --> 00:02:35,960 we're taught vowel space Opie 61 00:02:35,960 --> 00:02:40,040 Eckles in parentheses vs button capital 62 00:02:40,040 --> 00:02:46,220 B there dot text dot teach string and 63 00:02:46,220 --> 00:02:52,550 now value equals new number dot text 64 00:02:52,550 --> 00:02:56,990 that should be dr. string then I'm going 65 00:02:56,990 --> 00:02:59,060 to type if the next line parenthesis 66 00:02:59,060 --> 00:03:02,720 value done is not empty ending 67 00:03:02,720 --> 00:03:05,420 parenthesis and open a code block so 68 00:03:05,420 --> 00:03:06,880 that's the case we're going to perform 69 00:03:06,880 --> 00:03:12,230 operation value comma space o P and we 70 00:03:12,230 --> 00:03:13,430 haven't written that function yet so 71 00:03:13,430 --> 00:03:15,560 we're getting an error then outside of 72 00:03:15,560 --> 00:03:18,290 the order closing code block pending 73 00:03:18,290 --> 00:03:22,610 operation it was ap then on the last 74 00:03:22,610 --> 00:03:26,210 line to supply operation dot txt is 75 00:03:26,210 --> 00:03:29,330 equal two pending operation right this 76 00:03:29,330 --> 00:03:30,890 starts off very similar to what we've 77 00:03:30,890 --> 00:03:33,080 just done for the number buttons we 78 00:03:33,080 --> 00:03:34,550 create a new instance of onclicklistener 79 00:03:34,550 --> 00:03:37,130 and we saw in the instance to a variable 80 00:03:37,130 --> 00:03:39,530 called open listener that's on line 64 81 00:03:39,530 --> 00:03:42,470 now this method casts the do us a button 82 00:03:42,470 --> 00:03:44,660 then reads the text and assigns it to 83 00:03:44,660 --> 00:03:47,570 the string of variable opie on line 65 84 00:03:47,570 --> 00:03:49,790 and it also reads the number from the 85 00:03:49,790 --> 00:03:52,760 edit text widget new number and you can 86 00:03:52,760 --> 00:03:55,220 see it doing that on line 66 now there 87 00:03:55,220 --> 00:03:56,930 may not actually be any text though and 88 00:03:56,930 --> 00:03:59,000 there's nothing to stop the user from 89 00:03:59,000 --> 00:04:01,160 pressing in operation button before one 90 00:04:01,160 --> 00:04:03,290 of the numbers so before calling the 91 00:04:03,290 --> 00:04:05,180 perform operation method we're checking 92 00:04:05,180 --> 00:04:07,850 that the string is an empty on line 67 93 00:04:07,850 --> 00:04:09,440 now if there was something entered 94 00:04:09,440 --> 00:04:11,720 perform operation is called and that's 95 00:04:11,720 --> 00:04:12,980 the line that's currently showing an 96 00:04:12,980 --> 00:04:14,390 error because we haven't written that 97 00:04:14,390 --> 00:04:17,630 function yet but that's fine we won't we 98 00:04:17,630 --> 00:04:19,100 know we will need it just don't try to 99 00:04:19,100 --> 00:04:20,358 run the code until it's written because 100 00:04:20,358 --> 00:04:23,180 obviously it won't compile now whether 101 00:04:23,180 --> 00:04:26,120 perform operation was called or not the 102 00:04:26,120 --> 00:04:27,710 operation that got us here is near the 103 00:04:27,710 --> 00:04:29,510 pending operation and we're going to 104 00:04:29,510 --> 00:04:31,580 display that on the screen in the 105 00:04:31,580 --> 00:04:33,890 display operation textview and we're 106 00:04:33,890 --> 00:04:37,280 doing that on line 71 so all that 107 00:04:37,280 --> 00:04:39,020 remains is to assign the listener to the 108 00:04:39,020 --> 00:04:40,880 five buttons and at that point we've 109 00:04:40,880 --> 00:04:42,560 completed the first flowchart that we 110 00:04:42,560 --> 00:04:45,620 looked at in the previous video so let's 111 00:04:45,620 --> 00:04:47,690 go ahead and do that so it's going to be 112 00:04:47,690 --> 00:04:49,820 button equals 113 00:04:49,820 --> 00:04:52,940 doc said onclicklistener and it's going 114 00:04:52,940 --> 00:04:56,870 to be opener let's do the other ones as 115 00:04:56,870 --> 00:04:59,330 well we've got the divide multiply minus 116 00:04:59,330 --> 00:05:07,370 and plus then for each side miners we've 117 00:05:07,370 --> 00:05:12,950 got our multiplier and if you just do me 118 00:05:12,950 --> 00:05:14,890 consistent limits you have been divided 119 00:05:14,890 --> 00:05:17,000 multiplied at them with our miners on 120 00:05:17,000 --> 00:05:19,520 this line doesn't really matter so long 121 00:05:19,520 --> 00:05:21,860 as we've got all the buttons set up in 122 00:05:21,860 --> 00:05:23,960 this fashion so equals divide multiply 123 00:05:23,960 --> 00:05:25,580 minus and plus have all been assigned 124 00:05:25,580 --> 00:05:28,160 the only listener alright so we can't 125 00:05:28,160 --> 00:05:31,010 test it yet until we fix this or create 126 00:05:31,010 --> 00:05:35,240 this function and that perform operation 127 00:05:35,240 --> 00:05:37,100 method has a bit of work to do but so 128 00:05:37,100 --> 00:05:38,320 that we can test the program so far 129 00:05:38,320 --> 00:05:40,760 let's go ahead and create a dummy method 130 00:05:40,760 --> 00:05:42,890 that just displays the operation in the 131 00:05:42,890 --> 00:05:44,990 textview I'm gonna come down here 132 00:05:44,990 --> 00:05:48,680 private I'm saying method but obviously 133 00:05:48,680 --> 00:05:51,830 it's a function so private fail perform 134 00:05:51,830 --> 00:05:54,860 operation it's going to be in 135 00:05:54,860 --> 00:05:59,260 parentheses value colon string come up 136 00:05:59,260 --> 00:06:02,240 then we're going to have operation colon 137 00:06:02,240 --> 00:06:06,830 space and a string and we're just going 138 00:06:06,830 --> 00:06:07,910 to keep it pretty simple at the moment 139 00:06:07,910 --> 00:06:11,260 to supply operation dot text equals 140 00:06:11,260 --> 00:06:14,510 operation so it's just basically a dummy 141 00:06:14,510 --> 00:06:16,580 dummy method that displays the operation 142 00:06:16,580 --> 00:06:18,470 in the textview but it clears the error 143 00:06:18,470 --> 00:06:20,900 so that we can test our program again so 144 00:06:20,900 --> 00:06:24,500 if we actually run this again now go 145 00:06:24,500 --> 00:06:26,750 back to our emulator this time the 146 00:06:26,750 --> 00:06:28,370 numbers and decimal point should still 147 00:06:28,370 --> 00:06:30,530 work and when we press one of the 148 00:06:30,530 --> 00:06:32,990 operate the operations buttons they 149 00:06:32,990 --> 00:06:34,220 should be shown on the screen so we can 150 00:06:34,220 --> 00:06:36,890 still enter a couple of numbers here but 151 00:06:36,890 --> 00:06:38,690 then if I press some of the operations 152 00:06:38,690 --> 00:06:42,110 buttons there's our divide multiply 153 00:06:42,110 --> 00:06:46,070 minus plus equals they were working 154 00:06:46,070 --> 00:06:47,840 nicely and obviously we can enter other 155 00:06:47,840 --> 00:06:50,510 numbers as well and this the dot is 156 00:06:50,510 --> 00:06:53,120 where here's it should be so so far so 157 00:06:53,120 --> 00:06:53,390 good 158 00:06:53,390 --> 00:06:55,730 so let's finish this video here now and 159 00:06:55,730 --> 00:06:57,200 in the next video we're gonna get the 160 00:06:57,200 --> 00:06:59,600 perform operation method to perform the 161 00:06:59,600 --> 00:07:01,669 appropriate calculations so I'll see you 162 00:07:01,669 --> 00:07:04,630 in that next video