我的 ListView 行中有一个复选框,如下所示。
===========================================
[CheckBox] [TextView] [TextView] [TextView]
===========================================
xml代码在这里
<CheckBox
android:id="@+id/course_search_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:clickable="false"
android:focusable="false" />
而且我已经将复选框设置为不可点击和可聚焦,以便点击事件将传递给 ListView。
这里我想做的是当用户点击listview时,勾选CheckBox并将listview点击的位置添加到一个arraylist中。那么如何让 CheckBox 在 ListView 的 OnItemClickListener 中被选中呢?
请帮忙,谢谢。
最佳答案
您可以在 OnItemClickListener
中添加此代码:
public void onItemClick(AdapterView parent, View view, int position, long id){
CheckBox box = (CheckBox)view.findViewById(R.id.course_search_checkbox);
box.setChecked(true);
}
关于java - 如何在 OnItemClickListener() 中选中复选框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8333311/