首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

动态作图CheckedTextView

2012-08-27 
动态绘制CheckedTextView这几天需要用到一个动态的多选列表框,结果从资源文件中设置是没有问题的。例1:Chec

动态绘制CheckedTextView

这几天需要用到一个动态的多选列表框,结果从资源文件中设置是没有问题的。

例1:

CheckedTextView2=new CheckedTextView(this);CheckedTextView2.setText("test2");CheckedTextView2.setCheckMarkDrawable(android.R.attr.listChoiceIndicatorMultiple);myLayout.addView(CheckedTextView2);

?结果报了异常android.content.res.Resources$NotFoundException when programmatically setting android.R.attr.listChoiceIndicatorMultiple·····

理论上这样是没有问题的,可能在绘制时需要先取到id,在绘制吧。google了一下,解决了,关键代码如下

//根据数组id得到数组类型
TypedArray ta = getBaseContext().getTheme().obtainStyledAttributes(attrs);
//初始化绘制目标
Drawable indicator = ta.getDrawable(0);
CheckedTextView1=new CheckedTextView(this);
CheckedTextView1.setText("test1");
//得到绘制目标后放入选择框中
CheckedTextView1.setCheckMarkDrawable(indicator);

?

热点排行