【问题标题】:Android MultiSelectListPreference with "Select All" checkbox in the title标题中带有“全选”复选框的 Android MultiSelectListPreference
【发布时间】:2016-02-26 04:49:24
【问题描述】:

我是 Android 新手。我有一个 MultiSelectListPreference,我可以选中/取消选中所有框,可能通过类别标题旁边的“全选”复选框,简而言之是这样的:

这是我的偏好 xml 文件中的 MultiSelectListPreference:

<MultiSelectListPreference
    android:title="Items list"
    android:key="itemsList"
    android:entries="@array/list"
    android:entryValues="@array/listValues"
    android:defaultValue="@array/listValues">
</MultiSelectListPreference>

这里是数组:

<string-array name = "list">
     <item>Item 1</item>
     <item>Item 2</item>
     <item>Item 3</item>
     <item>Item 4</item>
</string-array>

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

有什么方法可以实现吗?

【问题讨论】:

    标签: android checkbox sharedpreferences selectall multiselectlistpreference


    【解决方案1】:

    setOnCheckedChangeListener(CompoundButton.OnCheckedChangeListener listener) 添加到标题中的复选框。 在 onCheckedChanged 回调中遍历 listadapter 中的所有项目并标记为选中

    并检查此answer

    【讨论】:

    • 嗨蚂蚁,感谢您的回答。由于我是菜鸟,首先我不知道如何将复选框放在多列表选择首选项中的标题旁边。此外,我已经检查了您链接的答案,但它似乎不适合我,或者很可能我不明白如何适应我的情况。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-25
    • 2014-06-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多