我不知道發生了什麼。我的代碼崩潰了,我找不到原因。指定的孩子已經有父母
我有一個LinearLayout,它是幾個WebView的容器。
LinearLayout variableContent = (LinearLayout) this.findViewById(R.id.variableContent);
for (int i=0; i<5;i++){
XMLModule modul = modulsRecuperats.get(i);
myWebView webview = new myWebView(this);
WebView customWebViewContainer = (WebView) this.mInflater.inflate(R.layout.customwebview, null);
customWebViewContainer = webview._clientSettings(customWebViewContainer,progressDialog);
customWebViewContainer.loadData(modul.getContent(), "text/html", "UTF-8");
variableContent.addView(customWebViewContainer);
}
並且調用addView時代碼崩潰。有這個錯誤:
Caused by: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
我找不到原因。你能幫我嗎?
它看起來像你的variableContent已經有一些內容。你可以做一個variableContent.removeView()然後調用for循環。 – lokoko 2013-05-13 07:37:34
但這沒有意義,因爲線性佈局是可以包含多個孩子的佈局...... – Reinherd 2013-05-13 07:40:11