循环设置视图中的元素属性 表示子控件索引是从0开始 你把log拿出来看下错误把 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 大神,图在次,我看不懂java的报错 转型异常了 你看下LinearLayout ll01 = (LinearLayout)findViewById(R.id.LinearLayout01); 是否获取正确 是否是checkbox的直接父控件 我是采用代码循环添加的方式,源码如下 String deptCode = Tools.ReadXml(xml, "deptcodelist"); String deptName = Tools.ReadXml(xml, "deptnamelist"); String[] deptCodeList;// 部门编码集合 String[] deptNameList;// 部门名称集合 deptCodeList = deptCode.split(","); deptNameList = deptName.split(","); LinearLayout ll = (LinearLayout) this .findViewById(R.id.LinearLayout01); for (int i = 0; i < deptCodeList.length; i++) { LinearLayout checkboxLinearLayout = (LinearLayout) getLayoutInflater() .inflate(R.layout.checkboxdoitem, null); // 获得checkbox.xml文件中的CheckBox对象 CheckBox cbItem = (CheckBox) checkboxLinearLayout .findViewById(R.id.checkBoxItem1); cbItem.setTag(deptCodeList[i]); cbItem.setText(deptNameList[i]); ll.addView(checkboxLinearLayout, i); }然后我修改代码为LinearLayout ll01 = (LinearLayout) findViewById(R.id.LinearLayout01);//循环赋值for(int i=1;i<=ll01.getChildCount();i++){ LinearLayout llItem=(LinearLayout)ll01.getChildAt(i); CheckBox cbItem=(CheckBox)llItem.getChildAt(i); cbItem.setChecked(cbItemCheck);}报错log如下图 for(int i=1;i<=ll01.getChildCount();i++)应该是for(int i=0;i<ll01.getChildCount();i++) 我把i=0改了,忘了改i<=,所以有错,目前好用了 问题出在这里LinearLayout checkboxLinearLayout = (LinearLayout) getLayoutInflater() .inflate(R.layout.checkboxdoitem, null); // 获得checkbox.xml文件中的CheckBox对象CheckBox cbItem = (CheckBox) checkboxLinearLayout .findViewById(R.id.checkBoxItem1); cbItem.setTag(deptCodeList[i]); cbItem.setText(deptNameList[i]); ll.addView(checkboxLinearLayout, i);你往II中添加的是LinearLayout,而不是CheckBox,当然无法将LinearLayout强制转换为CheckBox 我那种循环添加checkbox的方式,如果部门太多,直接有的就不见了,求教,LinearLayout不是会自适应高度么 我是采用代码循环添加的方式,源码如下 String deptCode = Tools.ReadXml(xml, "deptcodelist"); String deptName = Tools.ReadXml(xml, "deptnamelist"); String[] deptCodeList;// 部门编码集合 String[] deptNameList;// 部门名称集合 deptCodeList = deptCode.split(","); deptNameList = deptName.split(","); LinearLayout ll = (LinearLayout) this .findViewById(R.id.LinearLayout01); for (int i = 0; i < deptCodeList.length; i++) { LinearLayout checkboxLinearLayout = (LinearLayout) getLayoutInflater() .inflate(R.layout.checkboxdoitem, null); // 获得checkbox.xml文件中的CheckBox对象 CheckBox cbItem = (CheckBox) checkboxLinearLayout .findViewById(R.id.checkBoxItem1); cbItem.setTag(deptCodeList[i]); cbItem.setText(deptNameList[i]); ll.addView(checkboxLinearLayout, i); }然后我修改代码为LinearLayout ll01 = (LinearLayout) findViewById(R.id.LinearLayout01);//循环赋值for(int i=1;i<=ll01.getChildCount();i++){ LinearLayout llItem=(LinearLayout)ll01.getChildAt(i); CheckBox cbItem=(CheckBox)llItem.getChildAt(i); cbItem.setChecked(cbItemCheck);}报错log如下图151行报空指针异常 我那种循环添加checkbox的方式,如果部门太多,直接有的就不见了,求教,LinearLayout不是会自适应高度么我的xml所有的域都是LinearLayout,为什么还是变成这样 我那种循环添加checkbox的方式,如果部门太多,直接有的就不见了,求教,LinearLayout不是会自适应高度么LinearLayout 高度设置为 android:layout_height="wrap_content" 兄弟们,别纠结前面了,是我自己2了,没注意套用了LinearLayout,帮忙解决这个我动态添加checkbox的时候,高度问题 我那种循环添加checkbox的方式,如果部门太多,直接有的就不见了,求教,LinearLayout不是会自适应高度么是会自适应高度,但是如果LinearLayout不是可滚动的话,超过手机屏幕的内容就不会显示了。 我那种循环添加checkbox的方式,如果部门太多,直接有的就不见了,求教,LinearLayout不是会自适应高度么是会自适应高度,但是如果LinearLayout不是可滚动的话,超过手机屏幕的内容就不会显示了。你的意思是换行?例如每4个一行, 我判断if(i%4)给checkbox添加什么属性呢?我一直没解决这个 你这是宽度问题 不是高度问题-.- 外面套个HorizontalScrollView把 我那种循环添加checkbox的方式,如果部门太多,直接有的就不见了,求教,LinearLayout不是会自适应高度么我的xml所有的域都是LinearLayout,为什么还是变成这样LinearLayout的默认布局是横向的,你设置成垂直方向的就是,android:orientation="vertical" 我那种循环添加checkbox的方式,如果部门太多,直接有的就不见了,求教,LinearLayout不是会自适应高度么是会自适应高度,但是如果LinearLayout不是可滚动的话,超过手机屏幕的内容就不会显示了。你的意思是换行?例如每4个一行, 我判断if(i%4)给checkbox添加什么属性呢?我一直没解决这个最外层一个LinearLayout,设置为垂直布局,然后每4个一行放在一个LinearLayout,这个LinearLayout设置为水平布局。 TextView和EditText 问题 调研日本android软件 刚配置好的android的环境,运行HelloWorld报错 安卓数据库sqlite之cursor问题,求各位大神帮解决一下! 如何用listview显示sqlite里的数据? 程序完成后,真机测试遇到的问题,如下: OutputStreamWriter用UTF-8编码发中文字符的问题 关于Android WIFI接受数据报问题。。。 如何做一个类似物流图标信息的列表 求大神解决啊 有没有现成的数据可以调用的?求指导 怎么用proguard做混淆啊
大神,图在次,我看不懂java的报错
String deptCode = Tools.ReadXml(xml, "deptcodelist");
String deptName = Tools.ReadXml(xml, "deptnamelist");
String[] deptCodeList;// 部门编码集合
String[] deptNameList;// 部门名称集合
deptCodeList = deptCode.split(",");
deptNameList = deptName.split(",");
LinearLayout ll = (LinearLayout) this
.findViewById(R.id.LinearLayout01);
for (int i = 0; i < deptCodeList.length; i++) {
LinearLayout checkboxLinearLayout = (LinearLayout) getLayoutInflater()
.inflate(R.layout.checkboxdoitem, null); // 获得checkbox.xml文件中的CheckBox对象
CheckBox cbItem = (CheckBox) checkboxLinearLayout
.findViewById(R.id.checkBoxItem1);
cbItem.setTag(deptCodeList[i]);
cbItem.setText(deptNameList[i]);
ll.addView(checkboxLinearLayout, i);
}
然后我修改代码为
LinearLayout ll01 = (LinearLayout) findViewById(R.id.LinearLayout01);
//循环赋值
for(int i=1;i<=ll01.getChildCount();i++)
{
LinearLayout llItem=(LinearLayout)ll01.getChildAt(i);
CheckBox cbItem=(CheckBox)llItem.getChildAt(i);
cbItem.setChecked(cbItemCheck);
}
报错log如下图
.inflate(R.layout.checkboxdoitem, null); // 获得checkbox.xml文件中的CheckBox对象
CheckBox cbItem = (CheckBox) checkboxLinearLayout
.findViewById(R.id.checkBoxItem1);
cbItem.setTag(deptCodeList[i]);
cbItem.setText(deptNameList[i]);
ll.addView(checkboxLinearLayout, i);
你往II中添加的是LinearLayout,而不是CheckBox,当然无法将LinearLayout强制转换为CheckBox
String deptCode = Tools.ReadXml(xml, "deptcodelist");
String deptName = Tools.ReadXml(xml, "deptnamelist");
String[] deptCodeList;// 部门编码集合
String[] deptNameList;// 部门名称集合
deptCodeList = deptCode.split(",");
deptNameList = deptName.split(",");
LinearLayout ll = (LinearLayout) this
.findViewById(R.id.LinearLayout01);
for (int i = 0; i < deptCodeList.length; i++) {
LinearLayout checkboxLinearLayout = (LinearLayout) getLayoutInflater()
.inflate(R.layout.checkboxdoitem, null); // 获得checkbox.xml文件中的CheckBox对象
CheckBox cbItem = (CheckBox) checkboxLinearLayout
.findViewById(R.id.checkBoxItem1);
cbItem.setTag(deptCodeList[i]);
cbItem.setText(deptNameList[i]);
ll.addView(checkboxLinearLayout, i);
}
然后我修改代码为
LinearLayout ll01 = (LinearLayout) findViewById(R.id.LinearLayout01);
//循环赋值
for(int i=1;i<=ll01.getChildCount();i++)
{
LinearLayout llItem=(LinearLayout)ll01.getChildAt(i);
CheckBox cbItem=(CheckBox)llItem.getChildAt(i);
cbItem.setChecked(cbItemCheck);
}
报错log如下图
151行报空指针异常
我的xml所有的域都是LinearLayout,为什么还是变成这样
LinearLayout 高度设置为 android:layout_height="wrap_content"
是会自适应高度,但是如果LinearLayout不是可滚动的话,超过手机屏幕的内容就不会显示了。
是会自适应高度,但是如果LinearLayout不是可滚动的话,超过手机屏幕的内容就不会显示了。你的意思是换行?例如每4个一行, 我判断if(i%4)给checkbox添加什么属性呢?我一直没解决这个
我的xml所有的域都是LinearLayout,为什么还是变成这样
LinearLayout的默认布局是横向的,你设置成垂直方向的就是,android:orientation="vertical"
是会自适应高度,但是如果LinearLayout不是可滚动的话,超过手机屏幕的内容就不会显示了。你的意思是换行?例如每4个一行, 我判断if(i%4)给checkbox添加什么属性呢?我一直没解决这个
最外层一个LinearLayout,设置为垂直布局,然后每4个一行放在一个LinearLayout,这个LinearLayout设置为水平布局。