【发布时间】:2013-05-13 07:32:10
【问题描述】:
我不知道发生了什么。我的代码崩溃了,我找不到原因。
我有一个 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 时代码会崩溃。出现此错误:
引起:java.lang.IllegalStateException:指定的孩子已经有一个父母。您必须先在孩子的父母上调用 removeView()。
我找不到原因。你能帮帮我吗?
【问题讨论】:
-
看起来你的 variableContent 已经有一些内容了。你可以做一个 variableContent.removeView() 然后调用 for 循环。
-
但这没有任何意义,因为线性布局是可以包含多个孩子的布局......