Welcome back and the last video we saw how we can add an entry to the database.
Now let's have a look at how we can read from the database in order to get that list, pretty much of
all the entries that we have, because we want to display a list of all the different dates in which
we finished the exercise.
So I'm just going to create a new function here in my school Let Open Helper, which I'm going to call
get all complete.
Dates list.
And maybe completed the list will be a better name here, and this function should return an array list
of strings.
So array list of string.
Variables, all right, and then.
In there, I, of course, need to return something at one point, so I'm just going to return.
Now, for now, but then, of course, later on, I want to return a list, so let's create that list
that I want to return.
I'm just going to create a list, which will be a type of relist.
Because that's what we need to return, right?
A list of strings and a array of strings, to be precise, and then we need a database from which we
want to reach.
So here you saw we created the database variable or object that we needed in order to write.
So we inserted something.
But now we want to read from it.
And in order to do so, we create a new DB, which will be this readable database.
The next thing is I will create a cursor, so this cursor will be of DBE Roll Querrey.
And here I run a school code, so here I'm executing school code, which will be select staff from and
then the name of the table and the table name was table history.
And then you can or you must also pass in the selection args but I'm just going to pass null.
All right, so that's the rockery and now we have the cursus, so we can now go through every single
entry that is inside of our database and in order to do so, well, I'm just going to use a while.
So I'm just going to say while Curser Dot.
Move to next, so it's going to move to the next one, as long as there is an entry in the database
for that cursor and the cursor just selects everything from the table history.
So if we have five entries, then it's going to run five times this while loop here.
All right.
If it's just two entries, of course, just two times.
So what I want to do in here, I want to get to date value.
So date value.
We'll be.
The result of curser thought jet stream.
And from where do I want to get the strength?
Well, from Curser that get Collum index.
And the column index is the column completed date.
OK, so what's going on here?
Well, I'm checking the column, which is called Completed Date or actually it's called We have it up
here called Completed Date.
Well, it's called completed on the score date.
So I want to have a look at this column and I want to get that value.
So I want to only get the value from that specific column.
And I want it as a string and I want it at the curse of precision, so that means if we are in row one,
then I want to have the entry that is in the column for completed date for one.
And I want to store that in this variable called date value.
And then I want to add that they value to the list that we created earlier, so add date value because
they value will be of type string because the entry in our completed date column is actually of type
string.
So this list that we have here is a list will be filled up step by step with all the date values that
are inside of our database.
So that's what this value this.
And then once we are done going through all of them, we can close the cursor so cursor not close.
So we're done with the whole curser work so we can just close it afterwards, so we should even close
it afterwards.
And then, of course, we don't want to return now, but we actually want to return the list.
So let's do that here as we turn to list.
All right, so that's our spotlight open helper class, which helps us to work with databases, right?
But where do I actually need the database?
Well, I want to open in the history activity, the functionality.
I want to open the database and read whatever is in there.
So here I'm going to create a new function, which I'm going to call.
Private fund gets.
All completed dates.
OK, so this one is not going to return anything.
This one is just going to later on fill our list or to be more precise, our recital of you that we
still need to set up.
But generally, that's going to be the idea of this.
So what this needs is to get access to the SQLite open, help her.
And actually to this function here, and we've done that before in our Finnish activity where we used
to DB Hunter, so I'm just going to copy that code, the handler stuff.
I'm going to paste that in here because I will need to be handler here.
But then I don't want to call the add date function, but I actually want to call that get all completed
dates list and I want to stored it somewhere.
So I'm going to store that in this variable called All Completed Dates list.
OK, so this will also be a list, actually, to be more precise, it will be in the list because that's
what this function returns.
So if we call that function and we store whatever the result of it is, then we store and the list in
that all completed dates list is going to be in the list of strings.
And in order to display something, what I'm going to do is I'm just going to use a Falu here.
So I go through all of the elements in my all completed dates list for now, and I'm just going to log
it.
So I'm just going to say, OK, look, I.
That's.
It's going to be that hard, plus something like that.
OK, and we need to import log here, so let's do that real quick import log and now we should be able
to see all the entries that we have in our database now in order to not confuse this log with the other
one.
I'm going to call this one log history activity.
And of course, we need to call this function at one point.
And a good point would be in the uncreate directly.
So inside of my history activity in the uncreate, I'm just going to say, OK, get all the complete
dates.
And for now it's just going to display them in the log.
Nowhere, nowhere else for now.
And we can already test it.
So let's run it and see what's going to happen.
And here I'm just going to look for date.
OK, so there we are.
Let's go to the history.
And you could see state history activity already entered and you can see there are two entries.
So I ran the score twice, once at half past one and another time, just about two o'clock.
All right, so as you can see, it already works now.
We, of course, want to display it in here.
And because this video is so short, I'm just going to say, let's prepare the actual individual list
elements so the list items, how we want them to look.
So let's create a new XML file.
Inside of our.
Resources folder there in the layout folder, so I'm going to create a new XML file.
It will be a linear layout.
So the root element should be linear layout.
And the file name will be item on the score, his story on the score Ro.
All right, what do we want to have in there in this linear layout?
Well, for one, I want to have a little padding, so I'm going to add padding to the whole rope, so
to speak.
15 density pixels should be fine.
The orientation should be horizontal because I want to put the elements next to each other.
And then.
Background should be a very white color, so I'm going to use Ebbie SBB, it's not white as such, but
it's slightly gray just a little bit.
The layout height should be.
Rep content, so it shouldn't take the whole screen, but only as much space as it needs.
And I'm going to give it an idea, so let's give this linear layout an idea, I'm going to call this
one El Al history item main.
And you know what, I'm just going to paste a text use in here, because otherwise I'm probably going
to bore you to death because you've seen is a thousand times how to create a text to you.
So what I want to use is tools.
And when I do that, you can see it doesn't know this namespace.
So I will add tools namespace up here in my linear layout.
So this is how you can do it and now it's not going to complain about it anymore.
So the first text, you should only wrap its content and that in both directions.
So in the end tonight I'm going to call it TV position.
I'm going to send it from a gravity perspective with color size, which is a very dark gray or a black,
almost 16 as a textiles.
And the textile should be bold.
Now the tools text should be one.
And the second text view, I call it TV item, it has a width of zero because it should use the lighter
weight of one in order to determine how much space it's going to get.
And I just want to take all of the available space.
The gravity will be center.
Then the text color should be the same.
Text size and text style should be the same at the tools.
Text should be data.
What does that even mean?
Well, you can see that here.
So that's pretty much what it means in this view.
The item should look like this.
So we have a little bit of padding surrounding it, 15 density pixels and we have this text one and
then we have this date.
So that's how I want one last element to look like, OK, and that's already pretty much it for this
video.
In the next one, we are going to prepare our recycler view and the adapter in order to display all
of the dates that we have in our database.
OK, so see you in the next one.