1
00:00:00,950 --> 00:00:01,550
Welcome back.

2
00:00:01,790 --> 00:00:08,390
And this we have we are going to now use the details that we get from our debt picture dialogue and

3
00:00:08,390 --> 00:00:11,240
then display them for now, just in the toast here.

4
00:00:11,540 --> 00:00:15,290
So we'll get the here, we get the month and we get the day of the month.

5
00:00:15,560 --> 00:00:21,650
So let's go ahead and just use the year, for example, so we can just say year.

6
00:00:23,380 --> 00:00:26,560
Was and then the year here.

7
00:00:27,500 --> 00:00:29,000
And let's just say here.

8
00:00:29,420 --> 00:00:30,860
So let's test that once again.

9
00:00:31,830 --> 00:00:39,960
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

10
00:00:39,960 --> 00:00:44,490
say month was and then the month.

11
00:00:44,730 --> 00:00:45,750
So let's test it.

12
00:00:47,560 --> 00:00:54,220
And select a date, so the month was to September and I at sea and month was eight.

13
00:00:54,220 --> 00:00:55,630
Oh, September, isn't it?

14
00:00:55,630 --> 00:00:56,980
September is nine, right?

15
00:00:57,190 --> 00:00:58,210
So what's up here?

16
00:00:58,390 --> 00:01:04,510
Well, the problem is that months are calculated again in the programming way, starting from zero.

17
00:01:04,720 --> 00:01:10,090
So January is month zero, February is month one and so forth.

18
00:01:10,420 --> 00:01:17,530
So what we need to do is we need to add the one to the month year, for example.

19
00:01:17,680 --> 00:01:21,610
So plus one, let's see and test it again.

20
00:01:22,570 --> 00:01:31,210
So select the date and we can see month plus nine and then we can also use the day of month and.

21
00:01:32,480 --> 00:01:37,040
That would be day of month, and let's test that again.

22
00:01:38,300 --> 00:01:41,520
And we will see that it shows the 15th.

23
00:01:41,540 --> 00:01:45,920
So for some reason, the month is out of this world and starts at zero.

24
00:01:46,100 --> 00:01:47,370
That day, however, doesn't.

25
00:01:47,390 --> 00:01:50,090
So I don't know why that is, but that's how it is internally.

26
00:01:51,360 --> 00:01:59,190
Now we could make those names a little clearer, so we can say selected year, then selected month and

27
00:01:59,190 --> 00:01:59,760
so forth.

28
00:02:00,000 --> 00:02:04,770
This would make it a little more readable in terms of the coat.

29
00:02:05,130 --> 00:02:13,860
OK, so let's use those here instead selected the year and date of month, and we put that in another

30
00:02:13,860 --> 00:02:14,670
line here.

31
00:02:15,090 --> 00:02:15,630
Like So?

32
00:02:16,380 --> 00:02:22,590
OK, so now it will be a little more clear when it comes to the naming of those variables here.

33
00:02:25,100 --> 00:02:34,760
OK, so now let's go ahead and set of this text here, this one where it says 31st of May 1988 and display

34
00:02:34,760 --> 00:02:39,080
that instead, therefore we need to give this TextView a name an ID better set.

35
00:02:39,440 --> 00:02:41,270
So I'm going to give it an ID.

36
00:02:41,570 --> 00:02:46,400
You can go ahead and do it directly here, so click onto it and click here.

37
00:02:46,750 --> 00:02:51,350
Going to call the TV standing for text view, and I'm going to call this one selected date.

38
00:02:51,590 --> 00:02:56,840
OK, so this will be the I.D. I pressed the enter key for this to be taken over.

39
00:02:56,900 --> 00:02:59,690
And you will see that this text view here.

40
00:03:01,050 --> 00:03:05,880
This one that is selected, which will also be highlighted if you highlighted here, it will be highlighted

41
00:03:05,880 --> 00:03:07,770
in the designer as well.

42
00:03:08,160 --> 00:03:14,130
And you can see that this is in fact text view that has this idea of TV selected date.

43
00:03:14,640 --> 00:03:20,790
Now we can use that, we can just we use it in here in our click date picker.

44
00:03:21,120 --> 00:03:27,940
Unfortunately, however, we will need to create an eye while a new variable for it.

45
00:03:27,960 --> 00:03:34,590
So let's go ahead and create a new variable valve TV and how they call it T V.

46
00:03:35,590 --> 00:03:37,510
They are selected.

47
00:03:39,340 --> 00:03:45,190
Date, which is going to be of type, text view, Nullarbor.

48
00:03:46,060 --> 00:03:49,070
OK, and I will assign null to it for now.

49
00:03:49,330 --> 00:03:51,220
So we need to import it.

50
00:03:51,460 --> 00:03:55,120
You can see this widget here has been added to the widget.

51
00:03:55,120 --> 00:03:56,410
Text view has been added.

52
00:03:56,830 --> 00:04:03,310
So what I'm doing here is I'm creating this text view variable as a Nullarbor so that I can set it to

53
00:04:03,310 --> 00:04:08,890
null because I will not initialize it at this point, so I might assign a value to it at this point.

54
00:04:09,100 --> 00:04:16,240
I will leave it empty until the point where I'm going to actually assign it, and that is usually in

55
00:04:16,240 --> 00:04:17,320
the on create method.

56
00:04:17,350 --> 00:04:22,240
So it's a good practice to set it up in the on create method.

57
00:04:22,330 --> 00:04:29,020
So here TV's selected date will be found by its ID or Dot ID.

58
00:04:29,230 --> 00:04:30,100
And what was the name?

59
00:04:30,400 --> 00:04:37,900
Well, I called it TBE selected date and this is, of course, going to be a VAR here and not a vowel

60
00:04:37,900 --> 00:04:40,810
so that I can actually change it after it has been created.

61
00:04:41,320 --> 00:04:46,960
I'm creating this VAR and I also should make it private so that it's only going to be usable inside

62
00:04:46,960 --> 00:04:54,100
of this main activity and never accessible from another class because you don't want the situation to

63
00:04:54,100 --> 00:05:01,750
happen where you are accessing the UI element of an activity that is currently not in view, which means

64
00:05:01,750 --> 00:05:06,820
that an activity that you currently cannot see because if you tried to do that, your application will

65
00:05:06,820 --> 00:05:07,180
crash.

66
00:05:07,370 --> 00:05:07,750
OK.

67
00:05:08,050 --> 00:05:13,000
So what we're waiting here is exactly that by using this private key word for now.

68
00:05:13,600 --> 00:05:19,660
So we have this VAR TV selected date and now we can actually use it in our data picker dialog.

69
00:05:19,870 --> 00:05:28,680
So now we can store the selected year, month and day of month in the right format or in whatever form

70
00:05:28,690 --> 00:05:30,040
it we want to have.

71
00:05:30,250 --> 00:05:37,450
So I'm going to create a new variable called selected date, and I will just use string interpolation

72
00:05:37,450 --> 00:05:37,660
here.

73
00:05:37,660 --> 00:05:40,450
Selected and.

74
00:05:41,580 --> 00:05:50,250
In my case, I'm going to use day of month slash then the selected month, and here we need to use brackets

75
00:05:50,250 --> 00:05:56,700
right like two month plus one because we had this weird situation.

76
00:05:57,300 --> 00:06:02,550
And then another slash and selected year.

77
00:06:04,680 --> 00:06:10,170
Now we can set the text of our TV selected date, so in order to set the text, you can just choose

78
00:06:10,170 --> 00:06:11,430
to set text method.

79
00:06:12,000 --> 00:06:17,040
OK, so set the text with our selected date.

80
00:06:17,710 --> 00:06:18,150
Okay.

81
00:06:19,210 --> 00:06:24,580
And here, because this is a novel when he had the question mark.

82
00:06:24,760 --> 00:06:28,060
So set the text, that's one way of assigning a text.

83
00:06:28,060 --> 00:06:35,320
Another way is to just use the property so you can hover over here and see what the IDF has to offer

84
00:06:35,320 --> 00:06:35,950
for you.

85
00:06:36,310 --> 00:06:39,310
And here it says, to set use the property syntax.

86
00:06:39,310 --> 00:06:45,790
So that would be the alternative way here where you say TV selected date dot text and then you assign

87
00:06:45,790 --> 00:06:46,930
the selected text.

88
00:06:46,940 --> 00:06:52,300
So instead of using the set text method, which would be the old fashioned way, you can directly use

89
00:06:52,300 --> 00:06:54,760
the property of the selected date.

90
00:06:55,150 --> 00:06:56,500
OK, so let's test this.

91
00:06:56,830 --> 00:06:59,970
Let's see if it's actually going to display the selected date.

92
00:06:59,980 --> 00:07:04,630
So let's select the 15th and you see 15 nine 2021.

93
00:07:05,110 --> 00:07:10,030
So that seems to work, and it even is in that format that I just set.

94
00:07:10,120 --> 00:07:13,180
So day of the month, selected month, selected year.

95
00:07:15,000 --> 00:07:22,140
OK, so now we have the date in a certain format, but we need to have it in a data format in a sense

96
00:07:22,140 --> 00:07:31,140
of a date object so that we can then use it for calculating how much time has passed ever since.

97
00:07:31,740 --> 00:07:38,100
So in order to do that, I'm going to create a new variable called SDF, and this variable is going

98
00:07:38,100 --> 00:07:42,240
to be using the simple date format here and.

99
00:07:43,200 --> 00:07:51,000
What it allows us to do is, and here I'm going to use the simple data format like so and what it allows

100
00:07:51,000 --> 00:07:56,970
us to do is to define a pattern that we want to use for our date.

101
00:07:57,150 --> 00:08:02,850
So for example, if I want to use day to day, then month month and then year you year.

102
00:08:02,910 --> 00:08:06,330
So let's say the 31st of 05.

103
00:08:07,380 --> 00:08:10,770
Then in 1988, for example, then this would be the right format.

104
00:08:11,160 --> 00:08:16,470
And you can also define the local that you want to use.

105
00:08:16,740 --> 00:08:23,220
For example, the English format of using calendar dates or the French format and so forth.

106
00:08:23,430 --> 00:08:26,460
So local English will be the way to go here.

107
00:08:26,970 --> 00:08:33,539
So now we need to import simple date format, and I'm going to use the Java format here.

108
00:08:33,690 --> 00:08:35,340
So this java the text.

109
00:08:36,030 --> 00:08:39,600
OK, so this is the pattern, and then you need to pass to locale.

110
00:08:39,600 --> 00:08:42,330
So we're creating an object of the simple data format.

111
00:08:42,900 --> 00:08:49,890
And what this allows us to do is now to create an actual date object out of this as the F.

112
00:08:50,280 --> 00:08:54,810
So we're parsing from our selected date, which is just a string.

113
00:08:55,080 --> 00:09:03,750
We're converting that date here into the format that we want to use in a date object.

114
00:09:06,790 --> 00:09:12,520
And then this date object will later be used for us to calculate how much time has passed.

115
00:09:14,350 --> 00:09:18,280
By the way, just in order to make things a little clearer.

116
00:09:18,370 --> 00:09:24,670
So if you don't understand what a class does or if it goes over your head, if I ever use something

117
00:09:24,670 --> 00:09:31,480
like, for example, this simple date format, right now, I'm using this new simple date format class

118
00:09:31,480 --> 00:09:34,570
or before that I used to date picker dialog class.

119
00:09:34,870 --> 00:09:39,550
If you don't understand them, I always recommend to check out the documentation because you you'll

120
00:09:39,550 --> 00:09:43,870
find the simple date format and in particular, the one that we are using, which is under Java.

121
00:09:43,870 --> 00:09:44,440
That text?

122
00:09:44,620 --> 00:09:50,500
OK, so that's where you can find the data format class and you can find more details about it here,

123
00:09:50,770 --> 00:09:51,300
for example.

124
00:09:51,310 --> 00:09:54,790
Also with all of these letters mean so you have the AM.

125
00:09:54,790 --> 00:09:58,960
For example, the Capital M stands for month in a year.

126
00:09:59,230 --> 00:10:03,610
So here it would be July dual 07.

127
00:10:03,620 --> 00:10:07,690
So this would be the different formats, context sensitive.

128
00:10:08,170 --> 00:10:12,640
Or if you use a lower M, that would be the minute in an hour.

129
00:10:12,910 --> 00:10:14,050
So that's really important.

130
00:10:14,050 --> 00:10:21,370
That's why we were using the double M here as capital letters because lower caps M would be minutes.

131
00:10:21,850 --> 00:10:27,790
So D, let's look at what this means and D stands for day in month.

132
00:10:28,120 --> 00:10:33,310
OK, so day and month, which is a number, for example, the 10th or the 15th or whatever.

133
00:10:33,610 --> 00:10:37,550
And then finally, we have y y y, which stands for yea, yea yea.

134
00:10:38,260 --> 00:10:44,080
And here you can go over and see what is lower y means.

135
00:10:44,380 --> 00:10:51,160
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

136
00:10:51,160 --> 00:10:52,510
display in 1996.

137
00:10:52,840 --> 00:10:58,270
The single goes, by the way, also four month if you were to use M and it would display July.

138
00:10:58,270 --> 00:10:59,950
If it were, you use images.

139
00:10:59,950 --> 00:11:01,450
We'll just use zero seven.

140
00:11:03,440 --> 00:11:10,460
OK, but that's generally something that I'm trying to do is not to do too many things at once and not

141
00:11:10,970 --> 00:11:14,060
exaggerate how deep I go into something.

142
00:11:14,330 --> 00:11:18,890
So I'm trying to not bore you with going too deep into every single detail.

143
00:11:19,460 --> 00:11:24,230
And at the same time, give you enough information so that you get a good understanding of what's going

144
00:11:24,230 --> 00:11:24,500
on.

145
00:11:24,860 --> 00:11:30,950
But if you feel like there is something missing, so there is some class that you don't understand or

146
00:11:31,220 --> 00:11:38,960
some piece of code that you would like to know deeper or more about, then I really recommend to check

147
00:11:38,960 --> 00:11:44,030
out that documentation or Stack Overflow because I don't want to bore the ones that just want to go

148
00:11:44,030 --> 00:11:49,280
through with it and don't care about the specific details, but just want to know how to actually apply

149
00:11:49,280 --> 00:11:52,370
it rather than knowing everything in depth.

150
00:11:53,150 --> 00:11:58,730
OK, so that's just something that I wanted to give you as a side note, so let's finalize the application

151
00:11:58,730 --> 00:11:59,510
in the next video.

