我有一个带有自定义适配器的 ListView
。它包括复选框。当其中一个被选中时,我想取消选中其他的。我尝试创建一个 CheckBox
列表,然后创建一个方法来返回这个列表,但它一直给出 IndexOutOfBounds(我在 getView 方法中将 CheckBoxes 添加到列表中)。
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" />
最佳答案
为什么没有一个全局整数表示选中的位置,并在 getview 方法中查看全局变量的值和调用 getView 的位置是否相同,然后选中复选框,否则取消选中。
在 pastebin 中看到了你的代码。
你让它变得相当复杂。
无论如何,只是一个快速的评论,
不要做 this.pos=position;
在 getView() 中。
而不是这个检查 if(postion==this.pos){
//检查这个复选框
else{
//取消选中此复选框
}
此外,“pos”应由 Activity 控制或 pojo 本身处理数据列表。
关于java - Android 取消选中 ListView 上的复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8824286/