so running our application again we noticed the details is correctly being
shown here on the right hand side but the deadline is now not showing and
still does not show when we click on the item so let's go ahead and fix that and only we really
need to do is go down into our method here and within our
change method we need to add the code to show the deadline we're going to just put
that in their now so its going to be...
...because we want that
updated on the screen obviously as well
anytime the value changes once we do that and run it we can see our due dates appeared down the
bottom right hand corner of the screen and once we click on the different items we can
see the date is being updated as well so that's good that's fixed now and of course
we had to call the toString method again because the deadline is of type local date
be nice if we could display the date in a slightly better format because the way
it is now it a bit cryptic you probably saw on the screen it wasn't
really formatted nice and when we run the application particularly if the
day in the month was set for example to 4 or 3 it will be hard to know for sure it will be
talking about the month or the day or which part of the date is appropriate to
the date of the month so in other words so lets have a look at formatting the dates
so its easier to read so I'm gonna come up here in to the changed method and we are going
to introduce the concept of a date formatter
to be precise a date time formatter so....
....and we are going to talk about the the pattern shortly
so lets just type it exactly as you see here noting it has to be in the same
case as I'm typing so that's the pattern that we want the date to be displayed
in then we need to do is make sure that their deadline label talks to this def
project we created and then formats it correctly so we can do that by typing....
and that needs a date as opposed to a string so we need to remove the
.toString on the end
so now we've done that we should see our diet showing correctly or showing in a
different format than it did before and you can see its now showing April 25,
2016 which is a lot nicer and then change automatically based on the date
that we have selected so closing that down now if we open a browser and paste this link I got and you can see
link showing in the top left corner we've got more information about the
various values you can put into a date time formater and
scrolling down lots of different parameters and its giving some good examples you can use
some of these sort of hard coded formatters but looking down a little bit
further you can see its got a lot of other examples here as well it shows you all the
times of days the hour of day nano of a second week base year theirs lots of different formats and you just need to
use the appropriate symbol in the appropriate field or pattern to get it showing
in that format so for example if I wanted to change so its shows the day
of month I've put a d in their so lets go back and do that so put a d....what I'll do is comment that out so we can put that back if we need to but here we put....
...so that is one to how many days we are on a particular month we are in so month of year
would be an m and putting a space between the two and y would be a year or era
and gives you examples on the right hand side as to what to expect
the out put to be in so we could just put year and if I specify just two y as this time
we should see that it will only show us the value in two years like 04 for 2004
so lets try running that and we got another example 25 4 16 which isn't as readable as the last example
but the point is its actually working in that format
so you can experiment and changed and try different date styles if you like
but what I'll do is just put this one back in because I think the first one we got was a lot more readable so put
that in as.....so if we run it again you can see the dates is back to a nice format again and just
a note also that the spaces are important because obviously if we don't put
spaces in there
everything would be jumbled up together and be harder to read
still readable but not as readable as it was before so hence the use of space as well just to
space things out ok so at this point the basic UI is working it's not
pretty
we certainly won't release a product with this UI but it is functional so
let's take a second to think about what a user would want to do in addition to viewing
the to do list
obviously they want to add items to the list and of course we hard coded a few items because
we needed data to test the UI but if a user were to install this application their
wouldn't be any to-do items and also when they add to do items and then
close the application then they expect the to do items to be there next time they ran
the application so lets quickly add some code that will load and store to do items
in a flat file will start with storing the items and then we will run our
application so that it will save the hard coded items and you recall that the application
class which our main class extends has a stop method that we can override and
this will be a logical place to store our data however the controller will need the data
to populate the list view and it already has ready access to the list views
contents when we want to store them so for experience sake and because we doing
this quick and dirty way so that we can get back UI coding what we'll do is we'll
add a singleton class that both our main class and the controller can access
in a nut shell will use a singleton that we want there to be only one instance of
a class created over the entire run of the application
because of this the singleton class creates the one instance of itself and
we have talked about singleton's previously in the course it has a private
constructed to ensure that no other class will have a private constructor to
ensure that no other class can create an instance there's more toward than that
but the important thing for us is that the singleton usually contains a static
method that allows any class to get the single instance and call its methods
so lets look at writing that singleton class in the next video