Welcome back.
Now it's finally time to implement functionality in our code so that our web is actually intractable
so we can actually press the button, for example, and in order to do so, we go to the main activity
that you can find it in the Java.
And then your package name and then the main activity folder.
All right, so there is the main activity.
That's what's going to work with.
And what we can see here is, of course, we have our classman activity.
We have the package name here at the top with some imports that are auto generated for us.
And we have our uncreate function, which is called whenever our application is opening up this activity.
And in our case, this is the only activity and it's going to start with this activity.
So this is our start activity and an activity is just a screen.
All right.
So our activity main the screen will be displayed.
Why specifically this XML file?
Well, because we set it as the counterview.
So set counterview, we say, are totally outdoor activity, which is this activity that XML file.
All right.
In here.
What I want to implement is my button first.
So let's just use the button data picker.
As you can see, it defines this button directly.
So button data picker, that's openness and we can now use methods on it.
So for example, the set on Click Listener Method and here are two versions.
So one with a view, one without a view.
And I'm going to use the one with The View.
And in here I will for now just add a toast.
OK, so just so that we can test how our button works or if our button works at all, that we need a
context.
So I'm going to add this as the context, which means my main activity is going to be the context in
which the toast should be displayed.
Then the text should be button works.
And the length should be post thought length.
Long, let's just leave it there for a long time and of course, we need to show this.
So show.
OK, now I'm going to put this into different lines, so now it's a little more readable.
All right.
So we can see tost make.
Text will be displayed whenever we click on our button date picture.
So where does this button the picture coming from, maybe wonder?
Well, it's coming from our activity, main, and if we scroll down to our button, we can see it has
an ID called button date picture.
So between date picture and whatever the idea here is, we can directly exorcised in Scotland.
That's a pretty cool thing because in Java we would have to specifically create this object and stuff
like that.
So this is a lot easier and call it all right, now we can test it, so let's rerun it.
And let's click the button and we can see button works is being displayed here at the bottom.
So this is a little toast that we have here.
It's always great for specifically those testing purposes to see if a button works or the way it does
what we wanted to do once we interact with it.
Next, I would like to implement my data picker, so I want to open up this little thingy which displays
my calendar and then I can select a date.
So that's what I want to implement next.
But in order to do so, I will just create a new function.
So I'm going to create a function called Click Date Picker.
So fun.
Click Date Picker.
Now, what is going to be required as the parameter is going to be a view.
So I want this to be a view and it should be.
Called you, so I'm going to use view view and now I need to import view.
And if I do so, you can see my view has been imported and a view could be something that is displayed
on the screen, so it's just another type of element.
And if you look at our button date picture, you can see the set on click on this and now also has a
view here it view.
We're not using it, but it's there.
All right.
I cannot change it right now, but it's there.
So when I call this click data picture in here, so let's say I want to call it in there, click the
picture.
What I can pass is the view.
Now, where is this view coming from?
Well, it's actually coming from here, so I can directly say, you know, there's going to be what
is handed to me by the set on listening.
OK, so when we created it.
So let me create another button, the ticker that said you can see that there are two versions.
So one version was.
Without of you and the other one can see if you hover over it, it gets a view and then it executes
something.
So this is what this is all behind it.
So we get a view and then we execute something.
All right.
And that's what we do here.
We get the view and then we use the view and we use it to call this method called click data picker.
So we pass a view to this corrected picture.
Why is this important?
Well, it will be important as soon as we use the date pick dialog.
So there is a class called Data Picture Dialogue.
This class allows us to open up a date picture.
A dialogue is a type of pop up and we just say, OK, please open this pop up, which is a date picker.
And here we can.
Now go ahead.
And.
Use different type of parameters that we can pass here.
So what we will need to do is we need to pass.
Something to it.
So first of all, the context and then we need to pass.
The they'd picker dialogue date on date, and this one is with the Capitol Hill on a date set, listen.
All right, so we need to give it a on the set listen up, which needs and we're going to use this one,
which is a view a year, a month and so forth.
So as you can see, it requires all of those values view year, month, day of month.
So where do we get those from?
Well, the view luckily enough, we get from our.
Pardon data picker, so whatever set unclick listeners called, we get this view and we pass this view
to our method or function that we created here.
So this is the view that we got passed so we can use it in here by using this keyword view.
All right.
Next, we need a year, a month and so forth.
So let's create those let's create some variables.
Which are the.
Value and I'm going to call this one my calendar and then.
This is going to be calendar dot.
Gets instance, this will give us the instance in which we opened the calendar, so basically we are
using this calendar class, which allows us to create calendar objects, which we then can use.
So I'm creating this calendar object called my calendar, and I need to get a year, a month and a day
of a month.
All right.
So let's get the year and we get that from my calendar dot.
Get.
Kjellander.
That year, this will give us the current year.
Next, we need the month, so I'm going to create my calendar thought get.
And here, Kjellander dot month.
So in creating this new value, this new variable month, and the next one will be.
The date, which is, again, my calendar.
That get.
Kjellander.
That day.
On the score of.
On the score month and here, it's of course, easier if you type calendar correctly.
So now I have this view year, month and day of month, and now we will pass those values so that we
prepared here.
Over to this, they'd pick a dialogue and we do that behind those curly brackets, that's just a structure
that they have built here.
So we passed the year, we passed the month, and we passed a day.
Once we do that, you can see that the error disappears and it seems to be fine.
So I'm going to put those in different lines so that it's a little more readable.
All right, so we have the year, the month.
And so now whatever is behind this expression here will be executed once the date picker dialogue is
displayed.
Now, the thing is, I could directly displayed here so I could directly say that show.
All right, so I'm going to show the picture dialogue once this line of code is executed.
I would say it's a great time to test this, so let's go over to our app, let's rerun the code and
press select date and you can see this is the date picture and it took the current date, which is December
the 11th in twenty nineteen, which is a Wednesday.
And this is my date picture.
And if I press, OK, it's closing.
And of course, I didn't implement anything that should happen once that happens.
OK, so select date and you can see I can play around with it, I can select a different year, different
month and so forth.
So we have this.
They'd pick a dialogue on the set, listen up, and as I said, this is the code which comes afterwards
after this creators sign.
That will be executed.
So in my case, in line 37, I can execute some code and what I'm going to do is I'm just going to display
another toast just to see that it's working and it's going to say.
They'd picker works.
And instead of running a toast here, I'm going to get rid of this line, I don't want to display a
toast anymore.
Once we click on the button, they picture.
I just want to display it once we selected a date.
All right.
So let me rerun this.
So there we are.
I pressed the button today, Pickersgill still pops up, I selected eight Press, OK, and as you can
see, that picture works so well here at the bottom.
It says this picture works, which means that this code here was executed.
That's pretty cool.
So let's implement the code.
That should happen once we run this.
And what is the code that should happen once we selected the date?
Well, what we want to do is we want to display the date in minutes.
So it should do all of the calculation that is required to do so.
So in here, instead of in this case, line thirty two, I will have all of my logic that should be
executed once the date is selected.
And when is the date selected?
Well once we click on OK here.
All right.
So I click on OK and then the on date set listener is executed.
So it's very similar to what we had here set on Click Listener.
So we had an on Click Listener which waited for the click to happen and it listened, so to speak,
and once the click did happen, it started its code.
So it executed the code.
And in our case here on the set, listen to this one.
This listener here waits for the date to be set in our date to pick a dialogue, which is this little
pop up that we create here.
If I press cancel, however, you can see that dittos is not executed because we didn't select the date,
so we didn't set a date.
And so this onset listener was not executed.
All right, so that's it for now.
In the next video, we are going to start to implement the logic behind it that we want to run and I'd
say you the next video.