preferencecategory
Assuming there are multiple preference, we want to be able to organize them together. There are two ways in which we use preferencescreen to nest in composite preference, or to place the same preferencescreen side by side, in a way that has been introduced before and is not repeated. There is also a way to classify by prefrencecategory. XML files such as the following:
<preferencescreen xmlns:android= "http://schemas.android.com/apk/res/android" >
<preferencecategoryandroid: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 Healthy"/>
<checkboxpreference .../>
<checkboxpreference .../>
</PreferenceCategory>
<preferencecategoryandroid:key= "Vegitable_category"
android:title= "Vegetables"
android:summary= "Preference related to Vegetables" >
<checkboxpreference android:key= "Tomato_selection_pref"
Android:title= "Tomato"
android:summary= "It ' s actually a fruit." />
<checkboxpreference .../>
</PreferenceCategory>
</PreferenceScreen>
Child Preference
Sometimes, preference are dependent on each other, and B is valid only if a is true. The following example is, only choose the alarm, how the alarm will be effective, otherwise it will become gray. XML files such as the following:
<?xml version= "1.0" encoding= "Utf-8"?>
<preferencescreen xmlns:android= "Http://schemas.android.com/apk/res/android"
android:title= "@string/child_preferences" >
<preferencecategory android:title= "Alerts" >
<checkboxpreference android:key= "Alter_email"
android:title= "Send email?" />
<edittextpreference android:key= "Alter_email_address"
android:layout= "? Android:attr/preferencelayoutchild"
android:title= "Email Address"
android:dependency= "Alter_email"/><!--Set the association, only the key is Alter_email true, to enable the perf, the same time through the android:attr/format layout--
</PreferenceCategory>
</PreferenceScreen>
The sample code involved in this blog post can be downloaded in the Pro Android Learning: Preference (Preferences) sample.
RELATED Links: My Android development related articles
Pro Android Learning Note (Children's Day): Preferences (5): Organization preference