读书人

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

发布时间: 2012-07-25 09:43:06 作者: rapoo

如何设置点击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>

读书人网 >移动开发

热点推荐