如何在MultiSelectList preference设置多个默认值? [英] How to set multiple default values in a MultiSelectListPreference?

查看:1526
本文介绍了如何在MultiSelectList preference设置多个默认值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有preference.xml这样

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"
        />

我的两个数组:

    <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?

推荐答案

要做出默认选择(上)均 MultiSelectList preference 项目,则包括属性 defaultsValue 为preference,例如:

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 appliction data as this will only take effect the first time the application is run.

这篇关于如何在MultiSelectList preference设置多个默认值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆