ฉันมีเวลาที่ยากที่สุดกับข้อผิดพลาดนี้เนื่องจากสถานการณ์ที่ไม่ซ้ำกันของฉัน แต่ในที่สุดก็พบทางออก
สถานการณ์ของฉัน: ฉันใช้มุมมองแยก (XML) ซึ่งเก็บไว้WebViewแล้วเปิดในAlertDialogเมื่อฉันคลิกปุ่มในมุมมองกิจกรรมหลักของฉัน แต่อย่างใดหรืออื่นWebViewเป็นมุมมองที่กิจกรรมหลัก (อาจจะเป็นเพราะฉันดึงทรัพยากรจากที่นี่) ดังนั้นทางขวาก่อนที่ผมจะได้รับมอบหมายของฉันAlertDialog(ในขณะที่มุมมอง) ผมได้รับแม่ของฉันWebView, ใส่ลงViewGroup, ViewGroupแล้วลบทุกมุมมองว่า มันใช้งานได้และข้อผิดพลาดของฉันก็หายไป
// set up Alert Dialog box
AlertDialog.Builder alert = new AlertDialog.Builder(this);
// inflate other xml where WebView is
LayoutInflater layoutInflater = (LayoutInflater)this.getSystemService
(Context.LAYOUT_INFLATER_SERVICE);
View v = layoutInflater.inflate(R.layout.your_webview_layout, null);
final WebView webView = (WebView) v.findViewById(R.id.your_webview_id);
// more code...
.... ต่อมาหลังจากที่ฉันโหลดWebView....
// first, remove the parent of WebView from it's old parent so can be assigned a new one.
ViewGroup vg = (ViewGroup) webView.getParent();
vg.removeAllViews();
// put WebView in Dialog box
alert.setView(webView);
alert.show();