0

I need to create a settings screen, where only the first half contains preferences.

I was thinking on including a PreferenceFragment, but I need to support older devices (min supported API level is 9), and I also need to show the action bar (currently using appcompat library).

According to this question I'm screwed.

So now I need to replicate the look and feel of a preference list.

I've thought on including a ListView, and code a custom adapter that will provide a different item layout for each one of my "preference" types. I need to emulate CheckBoxPreference and ListPreference. The list preference is easy, as I just need to use the default layout for 2 text lines items (android.R.layout.simple_list_item_2), then show a custom dialog with the options. But I can't find in the built-in resources the layout for the checkbox preference.

I'll manage SharedPrefs on my own.

Questions:

  • Is there a better way of emulating preferences?
  • In case not, how could I copy or even reuse the built-in layout for checked list items? Is it available in android.R.layout? I need my custom adapter to return a layout that looks almost exactly as a CheckBoxPreference for boolean-like settings.
Community
  • 1
  • 1
Mister Smith
  • 27,417
  • 21
  • 110
  • 193
  • You can try this. https://github.com/kolavar/android-support-v4-preferencefragment/blob/master/src/android/support/v4/preference/PreferenceFragment.java – Yaroslav Mytkalyk Feb 06 '14 at 17:58

1 Answers1

2

I ran into this exact problem, which I didn't realize before I started implementing the support library. Bunch of work for nothing.

On the other hand, all old devices I needed to support with few exceptions where phones and not tablets. So I just used PreferenceActivity on those devices (check Build.VERSION.SDK_INT) and used PreferenceFragment only on SDK 11+ devices with tablet sized screens. You could even qualify the layout resource folders with the version number and screen sizes so you don't write any code.

MikeHelland
  • 1,151
  • 1
  • 7
  • 17
  • While it is true that `PreferenceActivity` was added in API 1, I can't use it because 1) I need action bar; and 2)I need to include non-preference related views in my screen. – Mister Smith Feb 07 '14 at 10:13