问题:java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
在弹出提示框中调用setview(WebView),WebView定义在单独xml布局文件中,
在activity加载时用一下代码初始化:
LayoutInflater aInflater = LayoutInflater.from(DemoActivity.this);
view_4d = (RelativeLayout)aInflater.inflate(R.layout.webview_4d, null);
提示框调用代码:
new AlertDialog.Builder(DemoActivity.this)
.setView(view_4d)
网上找原因和解决方案,在http://www.cnblogs.com/shenbin/archive/2012/03/15.html这篇文章中找到解决
思路,我用的是里面第一种方法,第二种方法是不能解决我的问题的,下面贴我修改之后代码:
public void onClick(View v) {
WebView self = new WebView(DemoActivity.this);
self.loadUrl("file:///android_asset/award/award.html");//加载本地html页面
new AlertDialog.Builder(DemoActivity.this)
.setView(self)
}
问题出现的原因可以从http://blog.csdn.net/lissdy/article/details/8453433这篇文章中得到启示