android remove view from alertdialog -
hi have mainactivity class have listview populated rss items. when click on item list app shows me alertdialog can see in message box item details. problem after show alertdialog when close , open new item app crashes giving me error:
fatal exception: main.lang.illegalstateexception: specified child has parent. must call removeview() on child's parent first.
here java class:
protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); listview = (listview) findviewbyid(r.id.listview); wv = new webview(this); try { url = new url("http://www.unikore.it/index.php/ingegneria-informatica-home?format=feed"); } catch (malformedurlexception e) { e.printstacktrace(); } new readrsstask().execute(url); listview.setonitemclicklistener(new adapterview.onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position,long id) { optiondialog = new alertdialog.builder(mainactivity.this).create(); optiondialog.settitle(listview.getitematposition(position).tostring()); s = rssitems.get(position).getdescription(); if(s.contains("href=")){ s.substring(0,s.indexof("</div>")); wv.loaddata(s, "text/html", "utf-8"); wv.setwebviewclient(new webviewclient() { @override public boolean shouldoverrideurlloading(webview view, string url) { view.loadurl(url); return true; } }); optiondialog.setview(wv); }else { optiondialog.setmessage(s.replaceall("<[^>]*>", "")); } optiondialog.show(); } }); }
i tried using optiondialog.dismiss()
method app crashes anyway.
thanks
move instantiation of webview
before accessing object.
s = rssitems.get(position).getdescription(); if(s.contains("href=")){ wv = new webview(this); wv.loaddata(s, "text/html", "utf-8"); // other code
Comments
Post a Comment