Search code examples
androidpreferences

how to return to the previous PrefenenceScreen from nested PreferenceScreen without press the back button


I have write a multi-level Preferences in program with xml File. and i want to know how to return to the previous level without press the back button. how to write some code to implement an item in preference to return previous Preferences level.


Solution

  • I think you are looking for something like this

    <?xml version="1.0" encoding="utf-8"?>
    <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
    android:key="NotifSettings" android:title="Notification Settings">
    <PreferenceCategory android:title="Notification Settings">
        <CheckBoxPreference android:key="NotifyOption"
            android:title="Notification Status" android:defaultValue="true"
            android:summaryOn="Notifications are Enabled." android:summaryOff="Notifications are Disabled."
            android:persistent="true" />
        <Preference android:title="XXXX"
            android:dependency="NotifyOption" android:summary="xxxxxx"
            android:key="Xxx" />
    </PreferenceCategory>
    
    <PreferenceCategory android:title="YYYYY">
        <PreferenceScreen android:title="Configure Notifications"
            android:summary="yyyyy">
    
            <CheckBoxPreference android:key="aa"
                android:title="aaaaa" android:defaultValue="true"
                android:summary="aaaa" />
    
            <CheckBoxPreference android:key="bb"
                android:title="bbbbb" android:defaultValue="true"
                android:summary="bbbb." />
    
            ...             
            <ListPreference android:title="zzz"
                android:summary="zzzz" android:key="zz"
                android:defaultValue="0" android:entries="@array/OverDesc"
                android:entryValues="@array/OverValues" />
        </PreferenceScreen>
    </PreferenceCategory>
    
    <PreferenceCategory android:title="Alert Type">
        <CheckBoxPreference android:key="AlertVibr"
            android:title="Vibrate" android:defaultValue="true"
            android:summaryOn="Vibration Turned ON" android:summaryOff="Vibration Turned OFF" />
    
        <CheckBoxPreference android:key="AlertSound"
            android:title="Sound" android:defaultValue="true" android:summaryOn="Sound Turned ON"
            android:summaryOff="MUTE" />
    </PreferenceCategory>
    

    But what I didnt get is that your want to return to the previous preference screen, without pressing back button. Can you shed some more light on that??