首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

怎么设置点击listview的任何位置都可以选中checkbook

2012-07-25 
如何设置点击listview的任何位置都可以选中checkbook在listview的OnItemClickListener中的onItemClick中控

如何设置点击listview的任何位置都可以选中checkbook
在listview的OnItemClickListener中的onItemClick中控制CheckBox就可以了:

@Overridepublic void onItemClick(AdapterView<?> arg0, View v, int position, long lpos) {CheckBox cb= (CheckBox) v.findViewById(R.id.is_check);if(cb.isChecked()){cb.setChecked(false);}else{cb.setChecked(true);}}


不过要先把CheckBox的focusable、focusableInTouchMode 和 clickable 设置为false:
<CheckBox android:id="@+id/is_check" android:layout_width="wrap_content"android:layout_height="wrap_content" android:layout_centerVertical="true"android:layout_alignParentRight="true"android:focusable="false"android:focusableInTouchMode="false" android:clickable="false"></CheckBox>

热点排行