Using PreferenceCategory : PreferenceCategory « Core Class « Android






Using PreferenceCategory

  

package app.test;

import android.os.Bundle;
import android.preference.PreferenceActivity;

public class Test extends PreferenceActivity
{
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.main);
    }
}

//xml/main.xml

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
        xmlns:android="http://schemas.android.com/apk/res/android"
                android:key="using_categories_in_root_screen"
                android:title="Categories"
                android:summary="Using Preference Categories">

    <PreferenceCategory
                android:key="meats_category"
                android:title="Meats"
                android:summary="Preferences related to Meats">

        <CheckBoxPreference
                android:key="fish_selection_pref"
                android:title="Fish"
                android:summary="Fish is great for the healthy" />
        <CheckBoxPreference
                android:key="chicken_selection_pref"
                android:title="Chicken"
                android:summary="A common type of poultry" />
        <CheckBoxPreference
                android:key="lamb_selection_pref"
                android:title="Lamb"
                android:summary="Lamb is a young sheep" />

    </PreferenceCategory>
    <PreferenceCategory
                android:key="vegi_category"
                android:title="Vegetables"
                android:summary="Preferences related to vegetable">
        <CheckBoxPreference
                android:key="tomato_selection_pref"
                android:title="Tomato "
                android:summary="It's actually a fruit" />
        <CheckBoxPreference
                android:key="potato_selection_pref"
                android:title="Potato"
                android:summaryOff="Yeah!"
                android:summaryOn="My favorite vegetable" />

    </PreferenceCategory>

</PreferenceScreen>

   
    
  








Related examples in the same category