android如何实现ListView中的CheckBox的全选、反选、全不选
2012-10-11 15:20
441 查看
http://blog.163.com/hjl_love_lx/blog/static/1209689902011723101742679/
1、全选
for (int index = 0; index < controlActionView.getChildCount(); index++) {
LinearLayout layout = (LinearLayout) controlActionView.getChildAt(index);
CheckBox checkBox = (CheckBox) layout.findViewById(R.id.isselected);
checkBox.setChecked(true);
}
2、反选
for (int index = 0; index < controlActionView.getChildCount(); index++) {
LinearLayout layout = (LinearLayout) controlActionView.getChildAt(index);
CheckBox checkBox = (CheckBox) layout.findViewById(R.id.isselected);
if (checkBox.isChecked()) {
checkBox.setChecked(false);
} else {
checkBox.setChecked(true);
}
}
3、全不选
for (int index = 0; index < controlActionView.getChildCount(); index++) {
LinearLayout layout = (LinearLayout) controlActionView.getChildAt(index);
CheckBox checkBox = (CheckBox) layout.findViewById(R.id.isselected);
checkBox.setChecked(false);
}
看了上面的代码是不是很简单呢,其实知识都这样,编程更是如此。在遇到问题时,感觉这个问题是多么的深不可测。然后通过各种方式去查找资料解决问题。当我们找到解决方案时,感觉都很简单。该ListView中的布局文件如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android
rientation="horizontal"
android:layout_height="match_parent">
<TextView
android:id="@+id/controlaction_id"
android:layout_height="0dip"
android:layout_width="0dip"
/>
<TextView
android:id="@+id/controlaction_code"
android:layout_width="180dip"
android:layout_height="wrap_content"
android:textSize="15pt"
/>
<TextView
android:id="@+id/controlaction_name"
android:layout_height="wrap_content"
android:layout_width="180dip"
android:textSize="8pt"
/>
1、全选
for (int index = 0; index < controlActionView.getChildCount(); index++) {
LinearLayout layout = (LinearLayout) controlActionView.getChildAt(index);
CheckBox checkBox = (CheckBox) layout.findViewById(R.id.isselected);
checkBox.setChecked(true);
}
2、反选
for (int index = 0; index < controlActionView.getChildCount(); index++) {
LinearLayout layout = (LinearLayout) controlActionView.getChildAt(index);
CheckBox checkBox = (CheckBox) layout.findViewById(R.id.isselected);
if (checkBox.isChecked()) {
checkBox.setChecked(false);
} else {
checkBox.setChecked(true);
}
}
3、全不选
for (int index = 0; index < controlActionView.getChildCount(); index++) {
LinearLayout layout = (LinearLayout) controlActionView.getChildAt(index);
CheckBox checkBox = (CheckBox) layout.findViewById(R.id.isselected);
checkBox.setChecked(false);
}
看了上面的代码是不是很简单呢,其实知识都这样,编程更是如此。在遇到问题时,感觉这个问题是多么的深不可测。然后通过各种方式去查找资料解决问题。当我们找到解决方案时,感觉都很简单。该ListView中的布局文件如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android
rientation="horizontal"
android:layout_height="match_parent">
<TextView
android:id="@+id/controlaction_id"
android:layout_height="0dip"
android:layout_width="0dip"
/>
<TextView
android:id="@+id/controlaction_code"
android:layout_width="180dip"
android:layout_height="wrap_content"
android:textSize="15pt"
/>
<TextView
android:id="@+id/controlaction_name"
android:layout_height="wrap_content"
android:layout_width="180dip"
android:textSize="8pt"
/>
相关文章推荐
- android如何实现ListView中的CheckBox的全选、反选、全不选
- android如何实现ListView中的CheckBox的全选、反选、全不选
- Android实战简易教程-第五十一枪(ListView实现子控件的动态显示和隐藏、checkbox全选和反选)
- Android ListView条目全选功能,不用checkbox实现!
- Android 带checkbox的listView 实现多选,全选,反选
- Android ListView+CheckBox实现全选、单选
- Android 带checkbox的listView 实现多选,全选,反选
- android基于ListView和CheckBox实现多选和全选记录的功能
- Android开发——listview中嵌套checkBox复选框实现单选、全选删除列表内容
- Android中ListView结合CheckBox实现数据批量选择(全选、反选、全不选)
- Android 带checkbox的listView 实现多选,全选,反选,删除
- Android 带checkbox的listView 实现多选,全选,反选
- android 基于ListView和CheckBox实现多选和全选记录的功能(转)
- Android 带checkbox的listView 实现多选,全选,反选
- Android基于ListView和CheckBox实现多选和全选记录的功能(转)
- 如何实现listView中checkbox的全选与反选功能
- Android ListView 中加入CheckBox/RadioButton 选择状态保持、全选、反选实现
- Android中ListView绑定CheckBox实现全选增加和删除功能(DEMO)
- Android checkbox的listView(多选,全选,反选)具体实现方法
- Android 带checkbox的listView 实现多选,全选,反选,删除