I have a ListView with a custom adapter. It countains CheckBoxes. When one of them is checked, I would like to have the others unchecked. I tried creating a CheckBox list, and then created a method to return this list, but it kept giving IndexOutOfBounds (I added the CheckBoxes to the list at the getView method).
The xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<CheckBox android:id="@+id/checkBoxListView"
android:layout_height="50px"
android:layout_width="50px"/>
<EditText android:id="@+id/editTxtListView"
android:layout_height="50px"
android:layout_width="680px"
android:editable="false"
android:focusable="false" />
why not have a global integer representing the checked position and in the getview method see if the global variable’s value and the position, for which getView is called, are same then make check box checked else unchecked.
Saw your code in the pastebin.
You are making it quite a complex thing.
Anyway, just a quick comment,
Dont do this.pos=position;
in the getView().
Instead of this check if(postion==this.pos){
//Check this checkbox}
else{
//uncheck this check box
}
Also, “pos” should be controlled by the activity or the pojo itself handling the data for the list.