4

I want to create a preferences screen without writing an XML layout file. I'd like to store the settings in a SQLite database. Is this possible?

Peter O.
  • 32,158
  • 14
  • 82
  • 96
  • How would your preferences screen know what to display, then? – Cat Nov 04 '12 at 22:40
  • If you don't want to use XML, don't want to use PreferenceManager, and want to store your own records, why not just make your own Activity, altogether? – Paul Burke Nov 04 '12 at 23:34

1 Answers1

1

You can simply create a preference hierarchy (probably in onCreate() for the PreferenceFragment) with:

PreferenceScreen screen = new PreferenceScreen();

and add preference items to screen using addPreference. In the PreferenceFragment (or PreferenceActivity, if you aren't using fragments), just call setPreferenceScreen with the hierarchy after it's constructed.

Ted Hopp
  • 232,168
  • 48
  • 399
  • 521
  • Sorry... i want to say that i I want to create a preferences screen without writing an XML settings file because i want to store all in my custom db sqlite. – user1798790 Nov 05 '12 at 08:43
  • @user1798790 - Why would you want to use an sqlite db instead of the built-in preferences storage system? It makes it harder to access the preference settings from elsewhere in your program and you lose the ability to listen for setting changes. (Plus, you then have to do a lot of other work because you can't simply use a `PreferenceActivity`.) – Ted Hopp Nov 05 '12 at 19:13
  • I would use only the GUi of preference screen and interface it with the db.non want the information to be saved in the xml file.thank – user1798790 Nov 05 '12 at 23:01