Il

Meats

[Vegetables
Figure 11-7. Using PreferenceCategory to organize preferences

Figure 11-7 shows the same groups we used in our previous example, but now organized with preference categories. The only difference between the XML in Listing 11-8 and the XML in Listing 11-7 is that you create a PreferenceCategory for the nested screens rather than nest PreferenceScreen elements.

Listing 11-8. Creating Categories of Preferences

<?xml version="1.0" encoding="utf-8"?> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"

<PreferenceCategory xmlns:android="http://schemas.android.com/apk/res/android" 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" />

android:key="using_categories_in_root_screen" android:title="Categories" android:summary="Using Preference Categories'^

<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 xmlns:android="http://schemas.android.com/apk/res/android" 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:summary="My favorite vegetable" />

</PreferenceCategory>

</PreferenceScreen>

0 0

Post a comment