1
我有一个自定义视图(扩展视图),我想在OnCreate函数中添加控件(按钮/文本框等),以在运行时将这些组件添加到视图中:将表单组件添加到自定义android视图
public Section(Context context) {
super(context);
this.setBackgroundColor(Color.argb(255, 242, 242, 242));
this.setOnTouchListener(mSectionOnTouch);
LinearLayout l = new LinearLayout(this.getContext());
l.setOrientation(LinearLayout.VERTICAL);
Button btn = new Button(this.getContext());
btn.setId(1);
btn.setText("btn1");
l.addView(btn);
Button btn2 = new Button(this.getContext());
btn2.setId(2);
btn2.setText("btn2");
l.addView(btn2);
} // Section
但这似乎没有做任何事情......有人能告诉我什么即时做错了吗?
非常感谢
FR
扩展LinearLayout而不是查看它 - 干杯:D – FiniteRed