私はこのコードを持っており、RelativeLayout( RelativeLayout->ScrollView->LinearLayout->My ChechBoxes) 内にネストされた ScrollView 内にネストされた LinearLayout 内に CheckBoxes を動的に追加したい
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);
しかし、私はこのエラーが発生します:
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.
XML ファイルで既に宣言されている RelativeLayout は、これをどのように修正できますか?