i have asynctask when onpreexecute function executes gives me exception
** java.lang.illegalstateexception: view com.android.internal.policy.impl.phonewindow$decorview@44ea0e20 has been added window manager.**
when progressdialog's show() method called.
my activity
public class topnewsactivity extends listactivity { public static final string log_tag = "infra"; private progressdialog progressdialog; /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.listplaceholder); new backgroundasynctask().execute(); } public class backgroundasynctask extends asynctask<string, integer, arraylist<hashmap<string, string>>> { @override protected void onpreexecute() { super.onpreexecute(); progressdialog = new progressdialog(topnewsactivity.this); progressdialog.setcancelable(true); progressdialog.setmessage("loading..."); progressdialog.setprogressstyle(progressdialog.style_spinner); progressdialog.setprogress(0); progressdialog.show(); } @override protected arraylist<hashmap<string, string>> doinbackground(string... paths) { arraylist<hashmap<string, string>> mylist = new arraylist<hashmap<string, string>>(); string xml = xmlfunctions.gettopnewsxml(); document doc = xmlfunctions.xmlfromstring(xml); int numresults = xmlfunctions.numresults(doc); log.d(log_tag, "number of results: " + numresults); if ((numresults <= 0)) { toast.maketext(topnewsactivity.this, "no result found",toast.length_long).show(); finish(); } nodelist nodes = doc.getelementsbytagname("result"); (int = 0; < nodes.getlength(); i++) { hashmap<string, string> map = new hashmap<string, string>(); element e = (element) nodes.item(i); map.put("id", xmlfunctions.getvalue(e, "id")); map.put("title", xmlfunctions.getvalue(e, "title")); mylist.add(map); } return mylist; } @override protected void onprogressupdate(integer... values) { super.onprogressupdate(values); } protected void onpostexecute(arraylist<hashmap<string, string>> result) { listadapter adapter = new simpleadapter(topnewsactivity.this, result, r.layout.list_item, new string[] { "title" }, new int[] { r.id.item_title }); setlistadapter(adapter); progressdialog.dismiss(); final listview lv = getlistview(); lv.settextfilterenabled(true); lv.setonitemclicklistener(new onitemclicklistener() { @suppresswarnings("unchecked") @override public void onitemclick(adapterview<?> a, view view, final int position, long id) { hashmap<string, string> o = (hashmap<string, string>) lv.getitematposition(position); intent = new intent(topnewsactivity.this, newsdetails.class); i.putextra("content_id", o.get("id")); i.putextra("title", o.get("title")); i.addflags(intent.flag_activity_clear_top); view v = topnewsgroup.group.getlocalactivitymanager().startactivity("shownews", i).getdecorview(); // again, replace view topnewsgroup.group.setcontentview(v); } }); } } public class mysimpleadapter extends simpleadapter { public mysimpleadapter(context context, list<? extends map<string, ?>> data, int resource, string[] from, int[] to) { super(context, data, resource, from, to); // todo auto-generated constructor stub } } }
please help!!!!!
there usual problem progressdialogs , contexts, happens me time , there's section on android doc exact problem. have declared context of "this" when context should name of java class followed ".this".
dialog = progressdialog.show(example.this, "", "doing stuff. please wait...", true);
this because want progressdialog show in main class, not in async class.
if doesn't solve it, you'll need post code.
Comments
Post a Comment