Search code examples
androidlistpreference

Custom “Select All” checkbox in ListPreference


I have implemented a custom ListPreference and managed to load a list of items along with checkboxes for each without an issue. However, I need to add a “Select All” checkbox on top in order to select all list of items. How would I achieve this with the following source I have implemented?

The layout:

<PreferenceScreen
        xmlns:android="http://schemas.android.com/apk/res/android">

    <PreferenceCategory
            android:title="@string/Title_LOCATIONS">       

        <com.gm.settings.LocationsListPreference         
            android:defaultValue="null"
            android:key="list_locations"
            android:title="@string/LocationsListPreference_title" 
            android:dialogTitle="@string/LocationsListPreference_title"
            android:summary="@string/LocationsListPreference_summary"
        />

The class:

public class LocationsListPreference extends ListPreference {
}

I have implemented the class by following a tutorial and it works fine. But it uses a default layout i think and if I were to add this addition checkbox, how would I achieve this?

Update:

I want to know as to how i can add the "Select All" checkbox to the layout? Or should i create a custom layout? Please provide a sample code. (Because i feel the way it is right now, i dont have the control over this checkbox)


Solution

  • Found a stackoverflow post which might help others if they come across this kind of implementation:

    You can build your custom ListPreference layout.

    Cheers!