I use a listview with multiple choice and I override the search method inside. I have a problem with the items in that during scrolling the position of items changed. The problem comes from the layout, I think, because when the layout includes only the listview, it works correctly. But, when I use the layout below, the positions of the items checked during scrolling get changed.
Can anyone help with that please?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/button1" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="Button" />
<ListView
android:id="@+id/MyListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/editText1" />
</RelativeLayout>
You need to set up an object in your adapter to keep track of the state of the checkboxes. You haven’t shown your adapter code so I’ll just pull an example from some of my code (this is using a cursor, it can be adapted to an ArrayAdapter)
In the custom adapter set an array:
In your constructor set your cursor to the local var and call a method:
The method (using 0 = not checked):
In your
getViewuse the array to set the checkbox state:You’ll need to add code in
checkBox.setOnCheckedChangeListeneralso to change the state in the array when you change the state of the checkbox.