Welcome back.
And this video, we are going to add a little functionality to our calculator, for example, I would
like the text to be displayed here in this text view, which currently is empty.
Once we click something, because for now, it just says button works, which is what we had in here,
this toast.
But we're not going to need this toaster anymore because we know that this button works.
And how did we implement this functionality?
Well, we went to our individual buttons and then we gave them this unclick property and assigned a
value here.
And the cool thing is it will automatically know, OK, once I click on this button, I should run this
on click event, which is called on digit.
Now, the thing is, it will automatically run this on digit function, which needs a view.
And this is generally the structure how we can implement those functions which need to be run with buttons.
So the view is going to be the button itself.
So it's going to know what kind of button was pressed and how is that important?
Well, it's important because I would like to know what Button was pressed.
So I would like to have the value that is inside of that button.
All right.
So, for example, the text that we see there, for example, of one or two or three, and in order
to get them and to display them on the TV input, which is our TextView that we created at the very
top here, this text you had had this TV input.
I would like to set its text that.
Text, so that would be one way thing is I want to actually.
Not only set the text, but I want to append something to that text once we click on it a button.
All right, once on digit function is called.
So I'm just going to append.
I text here, so let's just say we append test to it or I'm just going to say one.
All right, just for now, to keep it simple.
Now, this TV input is causing an error.
It says I need to import it.
Well, in my case, I had to import it because it comes from my activity.
Underscore main.
So in a case that's required for you, you can just go ahead and do so.
Now, we can test if this is actually going to run, because now the only difference really is that
once we click any of the buttons that has on digit implemented, then I think it's all of them except
for the equal sign.
Then the buttons should or the text should have a one on top here.
You can see there they are.
So it adds once up to the point where there are twelve values in there.
Why twelve?
Well, because we limited to twelve.
So we said max length should be twelve.
So not only twelve entries should be made in that text.
So now instead of just appending a one, I would like to spend whatever is written inside of the button
as its text.
So in this case, the seven once I click on the seven to eight when I click on the eight.
So how would I do that?
Well, the thing is, I can get the text from The View, but the view is of a different type than the
button itself.
So it's of a parent type.
So the button is inheriting from view.
So what we can do is we can cast this so we can say view as a button.
And then I would like to have the text from you.
So now I need to import button as well.
But as you can see now I get a text from a button doing so we can test that real quick just to see if
it's actually what I'm saying.
It is.
So I'm going to press a bunch of buttons and as you can see, they write whatever I enter.
And of course.
They are limited to 12 entries again or 12 digit.
Or letters in this case.
Now, the next thing that would be rather easy would be to implement the unclear functionality so the
functionality that should run once we clear where one wants to click on is clear.
So please try to implement that.
Just as a little hint, you need to set the text to empty or to an empty string.
All right, so I hope you tried it.
I'm going to implement it and I'm going to call this one on clear.
And again, we need to pass a view here or actually we need to get a view once we call this unclear.
And that is automatically done.
So we don't need to do it ourselves, but we still need to implement it here.
If you want to use the unclick functionality for one of our buttons and the one that I want to use it
for is the class, I'm just going to click on the seal are here and I'm going to call the unclear function
here.
So once unclick is called, so once we click on this clear button on Cleartrip call.
All right.
So now here, of course, we need to set the TV input.
The text to an empty string, and that's already it, so let's try this.
And in my case, just running restart didn't work because we also changed the XML file, so doing a
proper restart is what is required so that we are let's just match some buttons and then press clear.
And as you can see, the text was fully reset.
All right.
So that was the first little step to our application.
I'd say we check out the on decimal point functionality and the on operator functionality in the next
video.
So see you there.