all right so let's see if our
application works before we continue
adding more code I'm just going to start
my emulator and I'll just fast forward
this until it's are loaded
all right so emulator started so let's
run the application and just test this
out so want to make sure that all ten of
the numeric buttons work and also the
dock button and we're going to test it
in landscape as well that's particularly
important here because we're using a
different layout for landscape all right
so let's start there digits seven eight
nine four five six one two three zero
and click on the dot and I shouldn't be
able to click on the dot again that's
correct
so all ten of the digit buttons work and
the decimal point will only work once
and the reason for that by the way is
because we set the edit text to number
decimal in the layout an android takes
care of only allowing a single full stop
to be entered which saves us from having
to worry about checking the validity of
the number that's entered now if your
dot button doesn't work check the layout
if you made the edit takes just a number
signed in the layout then it won't
accept the decimal point you need that
number decimal as well alright so let's
quickly check landscapes working as well
so I'm going to just delete this delete
those numbers again seven eight nine
four five six one two three zero dot and
I can't press the dock more than once so
that's actually working well alright so
let's go back to the code now there's
still a bit of validation that we have
to code but so we're going to come back
to that later the moment though the
buttons are doing something in our
onclicklistener is working nicely so at
this point is now time to create the own
click listener for the operation buttons
now once again we're going to be passing
the actual view that causes the onclick
to be called so we'll read its text to
work out which operation it represents
I'm going to type the code in first and
then we'll go through this afterwards
we're going to do that below our button
code our set on click listeners for our
button code so valves base open listener
because view with a capital v dot on
click listener then we've got a left or
right curly braces and V dash greater
than sign then it's going to talk about
we're taught vowel space Opie
Eckles in parentheses vs button capital
B there dot text dot teach string and
now value equals new number dot text
that should be dr. string then I'm going
to type if the next line parenthesis
value done is not empty ending
parenthesis and open a code block so
that's the case we're going to perform
operation value comma space o P and we
haven't written that function yet so
we're getting an error then outside of
the order closing code block pending
operation it was ap then on the last
line to supply operation dot txt is
equal two pending operation right this
starts off very similar to what we've
just done for the number buttons we
create a new instance of onclicklistener
and we saw in the instance to a variable
called open listener that's on line 64
now this method casts the do us a button
then reads the text and assigns it to
the string of variable opie on line 65
and it also reads the number from the
edit text widget new number and you can
see it doing that on line 66 now there
may not actually be any text though and
there's nothing to stop the user from
pressing in operation button before one
of the numbers so before calling the
perform operation method we're checking
that the string is an empty on line 67
now if there was something entered
perform operation is called and that's
the line that's currently showing an
error because we haven't written that
function yet but that's fine we won't we
know we will need it just don't try to
run the code until it's written because
obviously it won't compile now whether
perform operation was called or not the
operation that got us here is near the
pending operation and we're going to
display that on the screen in the
display operation textview and we're
doing that on line 71 so all that
remains is to assign the listener to the
five buttons and at that point we've
completed the first flowchart that we
looked at in the previous video so let's
go ahead and do that so it's going to be
button equals
doc said onclicklistener and it's going
to be opener let's do the other ones as
well we've got the divide multiply minus
and plus then for each side miners we've
got our multiplier and if you just do me
consistent limits you have been divided
multiplied at them with our miners on
this line doesn't really matter so long
as we've got all the buttons set up in
this fashion so equals divide multiply
minus and plus have all been assigned
the only listener alright so we can't
test it yet until we fix this or create
this function and that perform operation
method has a bit of work to do but so
that we can test the program so far
let's go ahead and create a dummy method
that just displays the operation in the
textview I'm gonna come down here
private I'm saying method but obviously
it's a function so private fail perform
operation it's going to be in
parentheses value colon string come up
then we're going to have operation colon
space and a string and we're just going
to keep it pretty simple at the moment
to supply operation dot text equals
operation so it's just basically a dummy
dummy method that displays the operation
in the textview but it clears the error
so that we can test our program again so
if we actually run this again now go
back to our emulator this time the
numbers and decimal point should still
work and when we press one of the
operate the operations buttons they
should be shown on the screen so we can
still enter a couple of numbers here but
then if I press some of the operations
buttons there's our divide multiply
minus plus equals they were working
nicely and obviously we can enter other
numbers as well and this the dot is
where here's it should be so so far so
good
so let's finish this video here now and
in the next video we're gonna get the
perform operation method to perform the
appropriate calculations so I'll see you
in that next video