1

i try to create a multiplichoice listview, but i just can select one. Here is my code:

Selector (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>

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

Layout (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">

Somebody knows, why the multiselect isn't possible? Thanks a lot!!

Dimitri Dewaele
  • 10,311
  • 21
  • 80
  • 127
user3384194
  • 141
  • 1
  • 1
  • 11

1 Answers1

1

I personally made a custom ListView, with an array of ITEMS and an array of booleans the same size (initialized at false).

Each time a cell is clicked, it colors it and saves its state in the array of booleans (b = !b).

Worked great. I guess you got the idea, no code needed. If so, please tell.

shkschneider
  • 17,833
  • 13
  • 59
  • 112