============问题描述============
我有一个LinearLayout,里面都是checkbox,我想把LinerLayout里面的checkbox都变成选中状态,我的思路就是循环得到这个LinearLayout中的所有元素,然后转成CheckBox ,设置属性,但是转化的时候就是报错,估计不应该这样做,我的代码如下,红色为报错区
LinearLayout ll01 = (LinearLayout) findViewById(R.id.LinearLayout01);
//循环赋值
for(int i=1;i<=ll01.getChildCount();i++)
{
CheckBox cbItem=(CheckBox)ll01.getChildAt(i);
cbItem.setChecked(false);
}
============解决方案1============
表示子控件索引是从0开始 你把log拿出来看下错误把
============解决方案2============
for(int i=1;i<=ll01.getChildCount();i++)应该是for(int i=0;i<ll01.getChildCount();i++)循环设置视图中的元素属性
原文:http://www.cnblogs.com/qibileiru/p/4042013.html