LisetView中view布局
- XML code
<?xml version="1.0" encoding="UTF-8"?> <RelativeLayout android:gravity="center_vertical" android:orientation="horizontal" android:paddingLeft="5.0px" android:paddingTop="5.0px" android:paddingBottom="5.0px" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1.0" xmlns:android="http://schemas.android.com/apk/res/android"> <CheckBox android:id="@id/contact_checkbox" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_alignParentLeft="true" android:focusable="false"/> <LinearLayout android:orientation="vertical" android:id="@id/contact_item_layout" android:paddingLeft="8.0px" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_toRightOf="@id/contact_checkbox" xmlns:android="http://schemas.android.com/apk/res/android"> <TextView android:textSize="20.0sp" android:textStyle="bold" android:id="@id/contact_item_name1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_toRightOf="@id/contact_checkbox" /> <TextView android:textSize="14.0sp" android:id="@id/contact_item_name2" android:layout_width="fill_parent" android:layout_height="fill_parent" /> </LinearLayout> </RelativeLayout>
页面继承ListAcitivity
setListAdapter(baseadapter);
acitivity中有个selectAll点击它 怎样用程序代码实现checkBox的全部选中
------解决方案--------------------
- Java code
ListView listView = this.getListView(); int count = listView.getChildCount(); for(int i = 0; i < count; i++){ RelativeLayout layout = (RelativeLayout)listView.getChildAt(i); int c = layout.getChildCount(); for(int j = 0; j < c; j++){ View view = layout.getChildAt(j); if(view instanceof CheckBox){ ((CheckBox)view).setChecked(true); break; } } }