Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set multiple default values in a MultiSelectListPreference?

I have preference.xml like this

<MultiSelectListPreference
        android:key="store_select"
        android:title="@string/setting_store_title"
        android:summary="@string/setting_store_summary"
        android:dialogTitle="@string/setting_store_dialog_title"
        android:entries="@array/store_names"
        android:entryValues="@array/stores"
        android:defaultValue="@array/stores"
        />

with my two arrays:

    <string-array name="stores">
    <item>1</item>
    <item>2</item>
    <item>3</item>
    <item>4</item>
    <item>5</item>
</string-array>

<string-array name="store_names">
    <item>foodbasics</item>
    <item>nofrills</item>
    <item>metro</item>
    <item>loblaws</item>
    <item>sobeys</item>
</string-array>

I want the default behaviour to be all of the options selected, but currently nothing is selected by default. Am I doing something wrong?

like image 766
wangyif2 Avatar asked Mar 26 '13 02:03

wangyif2


1 Answers

To make all MultiSelectListPreference items selected (on) by default, then include the attribute defaultsValue for the Preference, e.g.

android:defaultValue="@array/stores"

If it's not working, then make sure that you clear the application data as this will only take effect the first time the application is run.

like image 73
SoftWyer Avatar answered Sep 24 '22 01:09

SoftWyer