Welcome back.
And this we have we are going to now use the details that we get from our debt picture dialogue and
then display them for now, just in the toast here.
So we'll get the here, we get the month and we get the day of the month.
So let's go ahead and just use the year, for example, so we can just say year.
Was and then the year here.
And let's just say here.
So let's test that once again.
And see if the selected year was 20 21 and you see it was 20 21, so now we can do the same thing and
say month was and then the month.
So let's test it.
And select a date, so the month was to September and I at sea and month was eight.
Oh, September, isn't it?
September is nine, right?
So what's up here?
Well, the problem is that months are calculated again in the programming way, starting from zero.
So January is month zero, February is month one and so forth.
So what we need to do is we need to add the one to the month year, for example.
So plus one, let's see and test it again.
So select the date and we can see month plus nine and then we can also use the day of month and.
That would be day of month, and let's test that again.
And we will see that it shows the 15th.
So for some reason, the month is out of this world and starts at zero.
That day, however, doesn't.
So I don't know why that is, but that's how it is internally.
Now we could make those names a little clearer, so we can say selected year, then selected month and
so forth.
This would make it a little more readable in terms of the coat.
OK, so let's use those here instead selected the year and date of month, and we put that in another
line here.
Like So?
OK, so now it will be a little more clear when it comes to the naming of those variables here.
OK, so now let's go ahead and set of this text here, this one where it says 31st of May 1988 and display
that instead, therefore we need to give this TextView a name an ID better set.
So I'm going to give it an ID.
You can go ahead and do it directly here, so click onto it and click here.
Going to call the TV standing for text view, and I'm going to call this one selected date.
OK, so this will be the I.D. I pressed the enter key for this to be taken over.
And you will see that this text view here.
This one that is selected, which will also be highlighted if you highlighted here, it will be highlighted
in the designer as well.
And you can see that this is in fact text view that has this idea of TV selected date.
Now we can use that, we can just we use it in here in our click date picker.
Unfortunately, however, we will need to create an eye while a new variable for it.
So let's go ahead and create a new variable valve TV and how they call it T V.
They are selected.
Date, which is going to be of type, text view, Nullarbor.
OK, and I will assign null to it for now.
So we need to import it.
You can see this widget here has been added to the widget.
Text view has been added.
So what I'm doing here is I'm creating this text view variable as a Nullarbor so that I can set it to
null because I will not initialize it at this point, so I might assign a value to it at this point.
I will leave it empty until the point where I'm going to actually assign it, and that is usually in
the on create method.
So it's a good practice to set it up in the on create method.
So here TV's selected date will be found by its ID or Dot ID.
And what was the name?
Well, I called it TBE selected date and this is, of course, going to be a VAR here and not a vowel
so that I can actually change it after it has been created.
I'm creating this VAR and I also should make it private so that it's only going to be usable inside
of this main activity and never accessible from another class because you don't want the situation to
happen where you are accessing the UI element of an activity that is currently not in view, which means
that an activity that you currently cannot see because if you tried to do that, your application will
crash.
OK.
So what we're waiting here is exactly that by using this private key word for now.
So we have this VAR TV selected date and now we can actually use it in our data picker dialog.
So now we can store the selected year, month and day of month in the right format or in whatever form
it we want to have.
So I'm going to create a new variable called selected date, and I will just use string interpolation
here.
Selected and.
In my case, I'm going to use day of month slash then the selected month, and here we need to use brackets
right like two month plus one because we had this weird situation.
And then another slash and selected year.
Now we can set the text of our TV selected date, so in order to set the text, you can just choose
to set text method.
OK, so set the text with our selected date.
Okay.
And here, because this is a novel when he had the question mark.
So set the text, that's one way of assigning a text.
Another way is to just use the property so you can hover over here and see what the IDF has to offer
for you.
And here it says, to set use the property syntax.
So that would be the alternative way here where you say TV selected date dot text and then you assign
the selected text.
So instead of using the set text method, which would be the old fashioned way, you can directly use
the property of the selected date.
OK, so let's test this.
Let's see if it's actually going to display the selected date.
So let's select the 15th and you see 15 nine 2021.
So that seems to work, and it even is in that format that I just set.
So day of the month, selected month, selected year.
OK, so now we have the date in a certain format, but we need to have it in a data format in a sense
of a date object so that we can then use it for calculating how much time has passed ever since.
So in order to do that, I'm going to create a new variable called SDF, and this variable is going
to be using the simple date format here and.
What it allows us to do is, and here I'm going to use the simple data format like so and what it allows
us to do is to define a pattern that we want to use for our date.
So for example, if I want to use day to day, then month month and then year you year.
So let's say the 31st of 05.
Then in 1988, for example, then this would be the right format.
And you can also define the local that you want to use.
For example, the English format of using calendar dates or the French format and so forth.
So local English will be the way to go here.
So now we need to import simple date format, and I'm going to use the Java format here.
So this java the text.
OK, so this is the pattern, and then you need to pass to locale.
So we're creating an object of the simple data format.
And what this allows us to do is now to create an actual date object out of this as the F.
So we're parsing from our selected date, which is just a string.
We're converting that date here into the format that we want to use in a date object.
And then this date object will later be used for us to calculate how much time has passed.
By the way, just in order to make things a little clearer.
So if you don't understand what a class does or if it goes over your head, if I ever use something
like, for example, this simple date format, right now, I'm using this new simple date format class
or before that I used to date picker dialog class.
If you don't understand them, I always recommend to check out the documentation because you you'll
find the simple date format and in particular, the one that we are using, which is under Java.
That text?
OK, so that's where you can find the data format class and you can find more details about it here,
for example.
Also with all of these letters mean so you have the AM.
For example, the Capital M stands for month in a year.
So here it would be July dual 07.
So this would be the different formats, context sensitive.
Or if you use a lower M, that would be the minute in an hour.
So that's really important.
That's why we were using the double M here as capital letters because lower caps M would be minutes.
So D, let's look at what this means and D stands for day in month.
OK, so day and month, which is a number, for example, the 10th or the 15th or whatever.
And then finally, we have y y y, which stands for yea, yea yea.
And here you can go over and see what is lower y means.
So here does y just means yea, as you can see here, so y y would display a nine six and y y y would
display in 1996.
The single goes, by the way, also four month if you were to use M and it would display July.
If it were, you use images.
We'll just use zero seven.
OK, but that's generally something that I'm trying to do is not to do too many things at once and not
exaggerate how deep I go into something.
So I'm trying to not bore you with going too deep into every single detail.
And at the same time, give you enough information so that you get a good understanding of what's going
on.
But if you feel like there is something missing, so there is some class that you don't understand or
some piece of code that you would like to know deeper or more about, then I really recommend to check
out that documentation or Stack Overflow because I don't want to bore the ones that just want to go
through with it and don't care about the specific details, but just want to know how to actually apply
it rather than knowing everything in depth.
OK, so that's just something that I wanted to give you as a side note, so let's finalize the application
in the next video.