12

I have a simple preference_headers.xml file. I want to add some categories on my preference headers. I have tried to implement <PreferenceCategory /> in my preference_headers.xml, but it doesn't work. I'm using API level 11. As shown in the figure below, Android Developers from official website can add the categories. How can I add it too?

categories on preference header

And here is a few of my preference_headers.xml code. It won't work:

<preference-headers xmlns:android="http://schemas.android.com/apk/res/android">

    <PreferenceCategory android:title="ACCOUNT" > 

        <header android:fragment="com.example.preferenceheader.SettingsFragmentAccount"
            android:title="@string/pref_header_category_account"
            android:summary="@string/pref_header_summ_account"
            android:icon="@drawable/ic_action_settings" />
    </PreferenceCategory>

    <PreferenceCategory android:title="APPLICATION" >

        <header android:fragment="com.example.preferenceheader.SettingsFragmentApplication"
            android:title="@string/pref_header_category_application"
            android:summary="@string/pref_header_summ_application"
            android:icon="@drawable/ic_action_group" />
    </PreferenceCategory>

</preference-headers>

Thanks for your help.

Anggrayudi H
  • 14,977
  • 11
  • 54
  • 87

2 Answers2

1

It's been close to a year since this was asked but I run into this example at http://www.101apps.co.za/articles/preference-settings.html that I think describes the requirement of the question in great detail and explanation.

I hope that it will help someone as it has helped me since it details the process of building a preference screen with categories and headers on the same page!

Cheers.

gnl
  • 151
  • 7
0

You need add header with only title. For example settings from AOSP

<!-- WIRELESS and NETWORKS -->
<header android:title="@string/header_category_wireless_networks" />

<!-- Wifi -->
<header
    android:id="@+id/wifi_settings"
    android:fragment="com.android.settings.wifi.WifiSettings"
    android:title="@string/wifi_settings_title"
    android:icon="@drawable/ic_settings_wireless" />
  • I'm not sure if this is entirely correct. The header with a single title, as proposed in your response, becomes a separate clickable header item when I try. Worth mentioning is that I'm using the `android.support.v14.preference.PreferenceFragment` which, in some mysterious way, may affect the outcome... – dbm Nov 14 '17 at 07:57