Android复选框不';t返回正确的值
我正在使用带有复选框的自定义listview。我想知道复选框是否被选中。因此,我使用getCheckedItemPositions()获取检查信息。如果我设置“android:clickable=“true”,复选框不会返回结果。但是,如果我设置“android:clickable=“false”,则视图中没有任何更改,但复选框返回其选中的信息。问题是什么?下面的代码是我使用getCheckEditePostions()和自定义ListView的XML代码的方法Android复选框不';t返回正确的值,android,xml,checkbox,Android,Xml,Checkbox,我正在使用带有复选框的自定义listview。我想知道复选框是否被选中。因此,我使用getCheckedItemPositions()获取检查信息。如果我设置“android:clickable=“true”,复选框不会返回结果。但是,如果我设置“android:clickable=“false”,则视图中没有任何更改,但复选框返回其选中的信息。问题是什么?下面的代码是我使用getCheckEditePostions()和自定义ListView的XML代码的方法 public void dele
public void deleteButton(View v)
{
int i,count;
count = mMyAdapter.mItems.size();
SparseBooleanArray checked = mListView.getCheckedItemPositions();
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal">
<CheckBox
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/checkBox1"
android:visibility="gone"
android:focusable="false"
android:clickable="false"
android:checkable="true"
android:layout_weight="1" />
<LinearLayout
android:layout_weight="4"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:layout_weight="1"
android:id="@+id/name"
android:layout_width="15dp"
android:layout_height="match_parent"
android:textSize="10pt"
android:text="name.." />
<TextView
android:layout_weight="1"
android:id="@+id/time"
android:layout_width="15dp"
android:layout_height="match_parent"
android:textSize="12pt"
android:text="name.." />
</LinearLayout>
<ToggleButton
android:layout_weight="1"
android:layout_gravity="right"
android:id="@+id/toggleButton3"
android:layout_width="6dp"
android:layout_height="match_parent"
android:text="Toggle"
android:textOff="Off"
android:textOn="On" />
</LinearLayout>
</LinearLayout>
public void delete按钮(视图五)
{
int i,计数;
count=mMyAdapter.mItems.size();
SparseBooleanArray checked=mListView.GetCheckEditePositions();
}
参考此“”检查此项。如果你没有得到答案,请通知我 参考此“”检查此项一次。如果你没有得到答案,请通知我 您需要实现setOnCheckedChangeListener,因为通过设置clickable false,在您无法获得更新值之后单击它将停止执行周期,所以请将其设置为true,但通过为每个复选框创建布尔变量,实现setOnCheckedChangeListener将复选框的状态保存为选中或未选中。那就行了
按照本教程实现onCheckedChangeListener:
您需要实现setOnCheckedChangeListener,因为通过设置clickable false,在您无法获得更新值之后单击它将停止执行周期,所以请将其设置为true,但通过为每个复选框创建布尔变量,实现setOnCheckedChangeListener将复选框的状态保存为选中或未选中。那就行了 按照本教程实现onCheckedChangeListener:
如何在ListView中的复选框上实现setOnCHeckedChangeListener?如果对您有效,请不要忘记将我的帖子标记为答案。快乐编码兄弟:)如何在ListView中的复选框上实现setOnCHeckedChangeListener?如果对您有效,请不要忘记将我的帖子标记为答案。快乐编码兄弟:)