Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I do "sub-categories" in Preferences

I have a Preference page where I would like 3 options "indented" or sort of like subcategories under the "custom flashcards" preference. Right now they are all under each other and seem like they are for different settings. How do I make it seem like subcategories of the "custom flashcards" preference. The three options only become enabled when custom flashcards is checked. Thank you!

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<   PreferenceCategory
android:title="Flashcard Selection"
android:key="flashcard_selection">
<CheckBoxPreference
    android:key="all_flashcards"
    android:summary="Display All Flashcards"
    android:title="All Flashcards"
    android:defaultValue="true" 
    />
<CheckBoxPreference
    android:key="custom_flashcards"
    android:summary="Display a customized list of flashcards"
    android:title="Custom Flashcards"
    android:defaultValue="false"/>
    <CheckBoxPreference
        android:key="red_flashcards"
        android:dependency="custom_flashcards"
        android:summary="Display Red Flashcards"
        android:title="Red"
        android:defaultValue="false"
        />
    <CheckBoxPreference
        android:key="yellow_flashcards"
        android:summary="Display Yellow Flashcards"
        android:title="Yellow"
        android:defaultValue="false"
        android:dependency="custom_flashcards"
        />
    <CheckBoxPreference
        android:key="green_flashcards"
        android:summary="Display Green Flashcards"
        android:title="Green"
        android:defaultValue="false"
        android:dependency="custom_flashcards"
        />
    <ListPreference
        android:key="frontside_preference"
        android:summary="Choose what do you want on your front side"
        android:title="Front side"
        android:entries= "@array/Frontside_selection_array"
        android:entryValues ="@array/Frontside_selection_values"
        android:defaultValue="1"
 />



</PreferenceCategory>
 </PreferenceScreen>
like image 567
compprogjava Avatar asked Aug 15 '13 20:08

compprogjava


1 Answers

One option to create a subcategory is to use a nested preference screen by switching the custom flashcards CheckBoxPreference tag to a PreferenceScreen tag and closing it after the three custom options. When the custom flashcard option is clicked, a new screen will appear with the three checkbox options.

<PreferenceCategory
    android:key="flashcard_selection"
    android:title="Flashcard Selection">
    <CheckBoxPreference
        android:defaultValue="true"
        android:key="all_flashcards"
        android:summary="Display All Flashcards"
        android:title="All Flashcards" />
    <PreferenceScreen
        android:defaultValue="false"
        android:key="custom_flashcards"
        android:summary="Display a customized list of flashcards"
        android:title="Custom Flashcards" >

        <CheckBoxPreference
            android:defaultValue="false"
            android:dependency="custom_flashcards"
            android:key="red_flashcards"
            android:summary="Display Red Flashcards"
            android:title="Red" />
        <CheckBoxPreference
            android:defaultValue="false"
            android:dependency="custom_flashcards"
            android:key="yellow_flashcards"
            android:summary="Display Yellow Flashcards"
            android:title="Yellow" />
        <CheckBoxPreference
            android:defaultValue="false"
            android:dependency="custom_flashcards"
            android:key="green_flashcards"
            android:summary="Display Green Flashcards"
            android:title="Green" />


    </PreferenceScreen>

</PreferenceCategory>

like image 85
Dave Justen Avatar answered Oct 09 '22 03:10

Dave Justen