1
我想補充一個textview
和checkbox
到linearlayout
觀點:指定的孩子已經有父母。你必須調用removeView()對兒童的父母第一次
for(int i = 0 ; i < helperitems.size() ; ++i){
final UserHelper u = helperitems.get(i);
runOnUiThread(new Runnable() {
@Override
public void run() {
LinearLayout linearLayout = new LinearLayout(ContentChatSendMessage.this);
linearLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
linearLayout.setGravity(Gravity.RIGHT);
ViewGroup.LayoutParams txt_view_params = new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
CheckBox ch = new CheckBox(ContentChatSendMessage.this);
ch.setId(Integer.parseInt(u.getId()));
linearLayout.addView(ch);
TextView textView = new TextView(ContentChatSendMessage.this);
textView.setLayoutParams(txt_view_params);
textView.setText(u.getUsername1());
linearLayout.addView(ch);
arr_chs.add(ch);
lay_lin_parent.addView(linearLayout);
}
});
}
我的佈局:
<LinearLayout
...
<LinearLayout
android:id="@+id/lay_lin_parent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="10dp"
android:layout_marginRight="4dp"
android:layout_marginLeft="4dp">
</LinearLayout>
...
</LinearLayout>
,但我得到這個錯誤:
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.