简体   繁体   中英

Create MultiSelectedListPreference using ArrayList

I'm trying to create a PreferenceActicity . I need that on of my preferences will be of type MultiSelectedListPreference .

I found this code on the internet:

<MultiSelectListPreference
    android:dialogTitle="@string/mode_repeat"
    android:key="mode_repeat"
    android:summary=""        
    android:title="@string/mode_repeat"
    android:entries="@array/weekdays"
    android:entryValues="@array/weekdays_values"
    android:defaultValue="@array/empty_array"
    />

The problem is I'm getting the entries and entryValues in runtime. I'm building the ArrayList while my app is running, the question is how can I set my ArrayList as the entries and as the entryValues ?

Do I need to create an empty xml file, which I will re-write during the building of my list?

You wouldn't be able to change the xml in runtime. The solution for your problem is to use the methods setEntries() and setEntryValues() from the MultiSelectListPreference class.

Here's a basic code snippet:

MultiSelectListPreference repeatModePreference = (MultiSelectListPreference) findPreference(Constants. mode_repeat);
repeatModePreference.setEntries(yourEntries); // This is human-readable strings
repeatModePreference.setEntryValues(yourEntryvalues) // The value corresponding to the human-readable string

Hope this helps.

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