简体   繁体   中英

Selecting default values for multi select list preference

I am working on an android app where I have implemented preference activity. I want to set more than one default values for Multi Select Preferences, how should I do it?

I want to do it programatically and not via layout

Try using :

listPreferenceData.setValues(defaultValue);

Here the defaultValue is the Set of the entry values which you wish to set as the default values.

Multi select ListPreference comes natively with Android from API level 11. For more information on this please check:

http://developer.android.com/reference/android/preference/MultiSelectListPreference.html

And for example ,you can check this http://blog.350nice.com/wp/archives/240

MultiSelectListPreference comes natively with Android from API level 11.

setValues method is used to set default value to MultiSelectListPreference.

void setValues (Set<String> values)

Sets the value of the key. This should contain entries in getEntryValues()

For example mListPref.setValue(defaultValue);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM