Search code examples
androidandroid-preferencespreferences

How to collapse rows of PreferenceCategory items after expanding it?


I would really like to know how can I collapse the Settings PreferenceCategory after I click on the arrow to expand and view its items (start, watch, value, country). I am able to expand the list but I am not able to find how to collapse the expanded list of items. Here is my Preferences xml file.

Preferences.xml

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceCategory
    android:key="settings"
    android:title="Settings"
    app:initialExpandedChildrenCount="0">
    <SwitchPreference
        android:defaultValue="false"
        android:key="Start"
        android:summary="Begin the race"
        android:title="Start" />
    <SwitchPreference
        android:defaultValue="false"
        android:key="watch"
        android:summary="watches"
        android:title="Watch" />
    <EditTextPreference
        android:defaultValue="1"
        android:dialogTitle="Value"
        android:enabled="false"
        android:key="value"
        android:title="Value"
        app:useSimpleSummaryProvider="true" />
    <EditTextPreference
        android:defaultValue="fr"
        android:dialogTitle="Country"
        android:enabled="false"
        android:key="country"
        android:title="Country"
        app:useSimpleSummaryProvider="true" />
    </PreferenceCategory>
</PreferenceScreen>

Solution

  • So for now, there is no way we can achieve that.