1

I have ListView with layout for row like which I inflate at adapter ( extend BaseAdapter ) at getView method

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <CheckBox
        android:id="@+id/chk"
        android:button="@drawable/q_list_check_box"
        android:layout_alignParentLeft="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_gravity="center_vertical"
        android:gravity="center_vertical"
        />
    <TextView
        android:id="@+id/txtChoice"
        android:textColor="@color/white"
        android:layout_gravity="center_vertical|left"
        android:gravity="center_vertical|left"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" /> 
</LinearLayout>

I put at ListView tag android:choiceMode="singleChoice". How to make list single choice, that only one row can be checked at time ?

Damir
  • 54,277
  • 94
  • 246
  • 365

1 Answers1

0

When I had to implement selection with my custom row., I used an arraylist of boolean to keep the state of the row. The size of boolean arraylist is same as rows of the listview. You can select/deselect the row via changing the value of corresponding boolean in OnListItemClick(). Anyways its just an idea. Here is a link that can help to understand this:

Custom List row with checkbox

Community
  • 1
  • 1
Khawar
  • 5,197
  • 4
  • 28
  • 52