【问题标题】:Multiple choice custom Listview多选自定义Listview
【发布时间】:2015-07-30 14:47:34
【问题描述】:

我尝试创建一个多项选择列表视图,但我只能选择一个。这是我的代码:

选择器(multiselect_background.xml):

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@color/blue" android:state_checked="true"/>
    <item android:drawable="@color/red" android:state_pressed="true"/>
    <item android:drawable="@color/grey"/>
</selector>

列表视图(list.xml):

<ListView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:choiceMode="multipleChoice"
/>

布局(select_item.xml):

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" 
    android:background="@drawable/multiselect_background">

有人知道,为什么不能进行多选?非常感谢!!

【问题讨论】:

    标签: android listview android-listview


    【解决方案1】:

    我亲自制作了一个自定义 ListView,其中包含一个 ITEMS 数组和一个布尔值数组,大小相同(初始化为 false)。

    每次单击一个单元格时,都会对其着色并将其状态保存在布尔数组 (b = !b) 中。

    工作得很好。我想你明白了,不需要代码。如果有,请告诉。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-01-10
    • 2021-03-05
    • 1970-01-01
    • 2016-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多