views:

85

answers:

1

Hello,

I would like to allow the user to enter (a non-predetermined amount of) values for an Android application preference. Existing examples that come to mind are the alarm clock applications found on various smartphones (iPhone, HTC Android, ...) where the user can add an alarm clock time.*

Can anyone think of a simple way to present an Android user with an extensible list of editable preference values?

So far I've thought of:

  • Comma separated values in a simple text field.
  • Limit the user to let's say 10 values and implement them as 10 editable preference items (EditTextPreference).
  • Make my own fancy sub-application just for these settings (although I'm not sure yet how I'd do that).

Any other ideas?

Chris

*(additional nice-to-haves along the lines of the alarm example would be: automatic ordering by value/time, a way to activate/deactivate certain values, a wheel for selecting numeric values similar to time and date selection wheels on the iPhone or Android).

+2  A: 

I would like to allow the user to enter (a non-predetermined amount of) values for an Android application preference.

Why preferences? Why not use a relational database, or your own flat file structure (e.g., JSON, CSV)?

Existing examples that come to mind are the alarm clock applications found on various smartphones (iPhone, HTC Android, ...) where the user can add an alarm clock time.*

What is your evidence that they use preferences? The alarm clock application does not use a PreferenceActivity, for example.

Can anyone think of a simple way to present an Android user with an extensible list of editable preference values?

Use a ListView, with an option menu choice to add items. Tapping on an item brings up an editor on that item, allowing for updates (and, via an option menu choice, deletes). After all, this is what the alarm clock application does.

automatic ordering by value/time

Teach your ListAdapter to sort.

a way to activate/deactivate certain values

Use a ListView set for CHOICE_MODE_MULTIPLE, with a CheckedTextView. Or manage your own checkboxes (the way the alarm clock application does).

a wheel for selecting numeric values similar to time and date selection wheels on the iPhone or Android

There are no "time and date selection wheels" in Android. There are the time and date pickers, which use buttons, not wheels.

You can view the source code of the alarm clock application to learn more about how it does what it does.

CommonsWare
Thank you so much, CommonsWare, for your great suggestions. For now, I did it with simple Preferences but of course experienced the limitations of this approach. I will keep you suggestions in mind for future improvements!
Chris Dickinson