【发布时间】:2018-04-22 08:46:09
【问题描述】:
我正在使用带有复选框的自定义列表视图。我想知道复选框是否被选中。所以我使用getCheckedItemPositions() 来获取checked_info。如果我设置 "android:clickable = "true" ",复选框不会返回结果。但是,如果我设置“android:clickable = “false””,视图不会发生任何变化,但复选框会返回其选中的信息。什么是问题?底部代码是我使用 getCheckedItemPostions() 和自定义 listiview 的 XML 代码的方法。
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>
【问题讨论】: