我不知道发生了什么。我的代码崩溃了,我找不到原因。指定的孩子已经有父母
我有一个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