I'm developing my first Android application, and I'd like to create a settings screen.
I'd like the screen to have a similar look-and-feel as the native phone-settings screens and the native "create/edit alarm" screen. Thus with different kinds of (statically defined) items vertically stacked with a thin line between them.
How do I define such screen?
I understand I can use the ListView, but this seems to be primarily meant for serving dynamic data using a ListAdapter, where each item is served in the same format. It seems to be possible to create different items (that is, some with checkbox, some with two text-lines, some with an icon) by creating my own ListAdapter and overriding getView but this seems like overkill. Should I be using a ListView for this purpose?
There's no need to manually create and format a ListView
- there are ways in the API to create Preference screens.
The most obvious is PreferenceActivity
.
You can define all your preferences in an XML file, a bit like a layout, and then load them with addPreferencesFromResource()
or you can create a number of PreferenceScreen
objects in code and populate them with Preference
objects that way.
The best thing do would be to look at the API Demos application provided with the Android API. This contains lots of good examples of managing preferences. Here's how it creates preferences from code and here's a sample preferences XML file. There are other examples showing more advanced things like preference dependencies and preference listeners.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With