views:

1684

answers:

3

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 (ie 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?

+11  A: 

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.

Dave Webb
Thanks! I missed that one.
Tomas
+3  A: 

Hi Tomas!

Try this: Android Preferences

Ungureanu Liviu
A: 

Actually in the built-in alarm application, for edit and create alarms, there is 2 activities, one for create and one for edit.

The Create Alarm activity is the first one with the digital clock.
The Edit Alarm activity is started by clicking on a listed alarm from the Create Alarm activity.

Edit Alarm implements PreferenceActivity but Create Alarm is more complex (custom cursor adapter to list the alarms).

Have a look at the sources :

kosokund