我有这样的代码,我要动态添加嵌套嵌套在RelativeLayout的内部滚动型内的LinearLayout(RelativeLayout-> ScrollView-> LinearLayout->我ChechBoxes)动态添加的LinearLayout成的RelativeLayout
li = (RelativeLayout) findViewById(R.id.mainlayout);
ScrollView sv = new ScrollView(this);
final LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
li.addView(sv);
sv.addView(ll);
for(int i = 0; i < 20; i++) {
CheckBox cb = new CheckBox(getApplicationContext());
cb.setText("I'm dynamic!");
ll.addView(cb);
}
this.setContentView(sv);
里面的CheckBox
,但我得到这个错误:
03-12 20:32:14.840: E/AndroidRuntime(945): Caused by: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
我的RelativeLayout在我的XML文件中声明已经 我是如何解决这一问题?
它不工作 – Fcoder 2013-03-12 21:50:53
我对不起,阅读,但我怎么可以帮助你没有任何有关_why_它不起作用的信息?我无法从这里看到您当前的代码或错误... – Sam 2013-03-12 21:55:29