G'day everyone. Welcome back, and welcome to section 14. In this section, we're going
to create a settings dialog for the app. Android Studio will generate a Settings
Activity for you, but I'm not going to use one. If you want to experiment with it,
you can find a Google guide at https://developer.android.com/guide/topics/ui/settings/
You can create a SettingsActivity by right-clicking the
project name and choosing New, Activity.
Near the bottom of the list, there's a SettingsActivity.
There are a lot of examples online, which is one reason I'm not going to use a
SettingsActivity here. Another reason is, we want the users to be able to change
things like the starting day of the week, while they're viewing the report.
A dialogue is more appropriate for that, because displaying a dialogue doesn't
involve leaving the Activity. Something else we'll do, is use a Preference Listener.
If the user does decide to change the starting day of the week, from
Sunday to Monday for example, then any report they're viewing should update
straight away. Whenever the preferences change, anything listening will be
notified of the change. That's much better than asking the user to restart
the app, when they change a configuration setting. If you followed along with
those menu options and started to create a SettingsActivity, click cancel.
We're gonna create a settings dialog instead. Okay, we're going to use string
resources for all the text, and to save typing, I'm gonna paste all the resources
into a resource file. We've created enough string resources for now, and I'm
sure you don't want to watch me type in more than necessary. I'll create a new
values resource file
called strings underscore settings.
That'll be in the values folder and then we'll paste in the resources. You'll find
the complete settings underscore strings.xml file in the resources for
this video, to save you doing the typing as well.
There's nothing special about the names of these resource files, and you can
create new files to organize things like your string resources. When your app is
built, all the XML files combined into a single resource file, and we looked at
the R class earlier in the course. I'm going to talk about those plurals
resources later, after we've seen them being used. We'll make a start on the
settings layout, in the next video. See you there.