Welcome back.
Now let's go ahead and create a refresh button in the menu of the application so that we can refresh
the weather so that we don't have to shut down the application and started again in order to get the
latest information of the weather or about the weather.
So, first of all, I'm going to create a new folder here, a new directory, which I'm going to call
menu.
And within our resources folder and inside of that menu, I want to create a new resource file, which
should be a menu.
So I'm going to call this one menu underscore main and the root element should be a menu.
All right.
So we can leave it as that.
And now we can go ahead and add an item to our menu.
So I just want to have an item in there and actually I'm going to use it like this, OK?
And then the settings that I want to assign to this item is going to be an ID so that we can access
it or we can communicate with it.
And that one will be action on the score refresh.
Then I need to assign an icon to it, and here I'm going to use at drawable and I'm going to create
a new icon, which I'm going to call icey refresh.
Twenty four deep.
All right, so of course, this doesn't exist, so let's go ahead and create a new vector so you can
vector it.
And here I'm using this, I can hear something sort of fresh, I can of course, you can use another
one, whatever you want as a refresh.
So there are alternatives here or other options, which also are refresh icons.
But I think the refresh.
Directly to refresh, I can should be fine as well.
So here, just search for refresh.
OK, and I'm going to call it, I see a refreshed 24 DP, the color should be white, so I'm using white
here next and finish.
All right, then you can see still complaining.
So there are still elements missing, so you need to specify the title.
All right, let's do that.
And I'm going to call the title refresh, even though just refresh should be a string.
So let's go out and create a new value in our string's.
Which I'm going to call action refresh, and the text should be refresh.
OK, now let's use this text here in our main menu.
So actually refresh and actually, to be more precise, at spring action refresh.
Then I'm going to set that order in category order in Category two 100, so this is going to pretty
much order your different icons.
And setting that to 100 is just the default here.
The order within the category applied to all items within this group.
OK, and then finally.
I'm going to set the show as action to true or actually to always so I want us to always.
Be an action.
All right, so how do I use a button at the top right corner of my application?
So what I want is to have this I can hear at the top, right, and when I click on it, it should refresh
everything, right.
So that's at least the idea behind it.
So how do we get there?
Well, we need to go to our main activity and then implement a few methods here, for example.
On options menu closed, well, that's an option, but on Create Options menu is the one that I actually
need and here in I can now inflate the menu.
I guess I can basically display the menu.
In order to do that, I can use the menu inflator dot inflate and here I need to pass on the menu that
I want to inflate and it's in my menu folder.
So in the resources press menu.
And then it's called Main or menu main.
And that's exactly the one that I want to use.
I know you need to pass in another variable and inflate so you can see it also needs a menu here.
So the menu to inflate into and I'm just going to say the menu here.
So it's going to be the menu that is passed to us by this uncreate options menu method, so this one
will be called as soon as the options menu is.
Created.
All right, and then we need to say what should happen once we click on that menu item.
So let's see if we can see the menu item at that point.
We should already see it here at the top because we implemented this uncreate options menu.
And we can see it's there at the top, but of course, clicking on it doesn't do anything yet.
So we need to implement on options item selected.
So once we click on it, we want to do something so you can see a return super, but I want to return
when so thing is, you could have multiple different menu items up there again.
That's why the category was added to this category order.
So it's not that you are limited to one item you could have.
I don't know how many items, depending on how many fit onto your screen, but you could have multiple
items in there, which is having one.
This is fine, but if you had more than you could, of course, have multiple things that you want to
execute based on the button, of course, that is pressed.
So in my case, what I want to do is I want to say when the item I.D. is our dot I.D., dot action underscore
refresh, which is this idea of the item of our refresh item, then I want to request the location data,
OK, because if we look at request location data and actually it's easier this way that we can see that
we get the location of the user and then we get the location callback and inside of location callback.
That's where we get a location where the details and yeah, that's certainly fine.
All right, now, let's go ahead and test that.
So although we are currently I'm in New York City, so I change the location, as you can see, and
now let's say I want to be in Allentown.
All right.
So I set the location to Allentown.
Let me close that and refresh the application, and you see, we are in Fort Lee, us, and the weather
is slightly differently.
All right.
OK, so as it seems, we still have an issue with our men and max temperature, we still get the same,
but that has to do with the API.
So nothing much we can do about it.
We could use a very different API call or a different website, or we could replace this whole cart
here with another cart or meaning it will still be the same card, but it's going to display different
information, such as, for example, the pressure or things like that.
All right.
So, yeah, now we pretty much have a finished application, so to speak, even though, of course,
we're still liking this feature.
But we're going to add some more features to this.
So let's do that in the next videos.
So it's either.