Question

I'm writing a configuration menu with many options and I'd like to add in the main PreferenceScreen an option that can launch an other PreferenceScreen.

I can't figure out how to create a generic menu entry (so, nor EditTextPreference nor CheckBoxPreference etc.)

Thanks to all.

Was it helpful?

Solution

Nest your PreferenceScreen elements. The inner PreferenceScreen will hold the contents of the second screen; the title and description you put on the inner PreferenceScreen will be your "generic menu entry".

For example:

<PreferenceScreen
    xmlns:android="http://schemas.android.com/apk/res/android">
    <PreferenceCategory android:title="Simple Preferences">
        <CheckBoxPreference
            android:key="checkbox"
            android:title="Checkbox Preference"
            android:summary="Check it on, check it off"
        />
        <RingtonePreference
            android:key="ringtone"
            android:title="Ringtone Preference"
            android:showDefault="true"
            android:showSilent="true"
            android:summary="Pick a tone, any tone"
        />
    </PreferenceCategory>
    <PreferenceCategory android:title="Detail Screens">
        <PreferenceScreen
            android:key="detail"
            android:title="Detail Screen"
            android:summary="Additional preferences held in another page">
            <CheckBoxPreference
                android:key="checkbox2"
                android:title="Another Checkbox"
                android:summary="On. Off. It really doesn't matter."
            />
        </PreferenceScreen>
    </PreferenceCategory>
    <PreferenceCategory android:title="Other Preferences">
        <EditTextPreference
            android:key="text"
            android:title="Text Entry Dialog"
            android:summary="Click to pop up a field for entry"
            android:dialogTitle="Enter something useful"
        />
        <ListPreference
            android:key="list"
            android:title="Selection Dialog"
            android:summary="Click to pop up a list to choose from"
            android:entries="@array/cities"
            android:entryValues="@array/airport_codes"
            android:dialogTitle="Choose a Pennsylvania city" />
    </PreferenceCategory>
</PreferenceScreen>

(which is from this sample project)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top