Pro Android Learning Note (Children's Day): Preferences (5): Organization preference

Source: Internet
Author: User

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>

<preferencecategory
android: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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.