i have created application having tab activity in turn has 5 different list activities in options menu there. till working fine since i've added asynctask options menu not work @ first instance when switch tabs , come first tab options menu opens on click.
code
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() { progressdialog = new progressdialog(topnewsgroup.group); 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(); return null; } 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 } } @override public boolean oncreateoptionsmenu(menu menu) { menuinflater inflater = getmenuinflater(); inflater.inflate(r.menu.optionsmenu, menu); return true; } @override public boolean onoptionsitemselected(menuitem item){ switch (item.getitemid()){ case r.id.refresh: startactivity(new intent(this, topnewsgroup.class)); return true; case r.id.search: startactivity(new intent(this, searchactivity.class)); return true; case r.id.info: startactivity(new intent(this, topnewsgroup.class)); return true; case r.id.exit: finish(); return true; } return false; } }
please help.
as use activitygroup needed override following functions display optionsmenu
@override public boolean oncreateoptionsmenu(menu menu) { return this.getcurrentactivity().oncreateoptionsmenu(menu); } @override public boolean onoptionsitemselected(menuitem item) { return this.getcurrentactivity().onoptionsitemselected(item); }
Comments
Post a Comment