Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Pattern for Preferences / Settings

Most apps have some kind of preferences or user settings that can be stored via the SharedPreferences. My first implementation of an activity for the user to edit his settings was pretty straight forward: a couple of input fields and a 'Save' Button. This is neither pretty nor easily extensible.

The android system settings and many apps that I have seen tend to layout their preference editing in ListViews.

My second approach tries to imitate this: a ListActivity and every item has to supply it's own layout, since I want to store different types of values (some are numbers, some are boolean radio buttons).

I am finding it rather cumbersome to implement this and now I am wondering if I am missing some obvious design pattern here?

like image 715
Yashima Avatar asked Mar 01 '11 17:03

Yashima


1 Answers

Just use PreferenceActivity, it will build the UI and handle the preferences persistence for you. Here you have more documentation:

  • http://developer.android.com/reference/android/preference/PreferenceScreen.html
  • http://jetpad.org/2011/01/creating-a-preference-activity-in-android/
  • http://www.kaloer.com/android-preferences
like image 190
Cristian Avatar answered Sep 24 '22 00:09

Cristian