关于android自定义控件动态添加的初始化问题 本帖最后由 jiokoi1989 于 2011-11-10 22:15:52 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 加一个构造函数public ChooseItem(Context context){super(context);} 我控件类里面两个构造函数都继承了,你写的那个我也有写。如果只是context还好,但我定义的那个控件必须是在(Context context, AttributeSet attrs)参数下的构造函数里面实现,也就是说我要是new一个ChooseItem,我也要new ChooseItem( Context, AttributeSet)。现在我就是不知道到底传什么样的实参,特别是AttributeSet。 不可以诶,编译没问题,一在模拟器里面就报错了。我用的是ChooseItem ctemp = new ChooseItem(this,null);listLinearLayout.addView(ctemp);但一运行就错了。 ChooseItem ctemp = new ChooseItem(this,null);LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);ctemp.setLayoutParams(params);listLinearLayout.addView(ctemp); 我傻了,没有初始化listLinearLayout,现在运行没问题了!太感谢你了!!! appwidget没响应update事件,求解(在线等) 【请问-------------】如何取得字符串的宽度(包含字间距的) new Intent(Intent.ACTION_VIEW); FFMpeg移植出问题 关于android 内存管理的问题 屏蔽所有的鼠标事件? Android_页面随输入法上移 正则表达式用来查询哪一段中有abc并且有rt的方法是什么呢? 做APP开发时,产品有提交RP设计原型吗 android studio混淆打包过程中遇到的问题,求大神!! try sleep后toast无法正常显示 Android当中可以用request和response吗?
super(context);
}
如果只是context还好,但我定义的那个控件必须是在(Context context, AttributeSet attrs)参数下的构造函数里面实现,也就是说我要是new一个ChooseItem,我也要new ChooseItem( Context, AttributeSet)。现在我就是不知道到底传什么样的实参,特别是AttributeSet。
不可以诶,编译没问题,一在模拟器里面就报错了。我用的是
ChooseItem ctemp = new ChooseItem(this,null);
listLinearLayout.addView(ctemp);
但一运行就错了。
ChooseItem ctemp = new ChooseItem(this,null);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
ctemp.setLayoutParams(params);listLinearLayout.addView(ctemp);
太感谢你了!!!