android - How to update the List whenever the tabs are changing in view pager -
in app using navigation tab using view pager. have able drawn tabs using code posted on:
https://github.com/codepath/android_guides/wiki/sliding-tabs-with-pagerslidingtabstrip
here have used sliding tab , view pager both navigation tabs.everything working fine list not getting updated when moving other tab. onresume() getting called object list variable getting updated while debugging visually list not getting updated.
here snippets of code:
for tab1 : in case active tab
@override public void onresume() { super.onresume(); if(!internetutil.isconnectedtointernet(getactivity())){ mswiperefreshlayout.setenabled(false); }else{ mswiperefreshlayout.setenabled(true); new getusersfromservertask().execute(); // here making network calls } }
on tab2 : archive tab
@override public void onresume() { super.onresume(); new getusersarchivedfromservertask().execute(); // network calls }
in mainactivity:
public class materialtab extends fragmentactivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.material_main_sample); viewpager viewpager = (viewpager) findviewbyid(r.id.viewpager); viewpager.setadapter(new samplefragmentpageradapter(getsupportfragmentmanager())); pagerslidingtabstrip tabsstrip = (pagerslidingtabstrip) findviewbyid(r.id.tabs); tabsstrip.setviewpager(viewpager); tabsstrip.setonpagechangelistener(new viewpager.simpleonpagechangelistener() { @override public void onpageselected(int position) { if(position == 0){ activefragment activefragment = new activefragment(); final fragmenttransaction ft = getsupportfragmentmanager().begintransaction(); ft.detach(activefragment); ft.attach(activefragment); ft.commit(); } if(position == 1){ archivefragment archivefragment = new archivefragment(); final fragmenttransaction ft = getsupportfragmentmanager().begintransaction(); ft.detach(archivefragment); ft.attach(archivefragment); ft.commit(); } } }); } }
also thing when doing swiperefresh list getting updated. totally confused why behaviour. when swiping tab same methods getting called , thelist not getting updated when doing swiperefresh it's getting updated.
this active fragment:
public class activefragment extends fragment { public void updatefragment(){ new getusersarchivedfromservertask().execute(); } public class getusersarchivedfromservertask extends asynctask<user, void, string> { @override protected string doinbackground(shipment... parmas) { // log.d(tag, string.valueof(shipmentdbhandler.getallactiveshipments().size())); _userlist1 = userdbhandler.getallactiveuserbytoday(datetimeutil.getcurrenttime()); return ""; } @override protected void onpreexecute() { super.onpreexecute(); } @override protected void onpostexecute(string str) { // set refresh listener false after list has been loaded new set of data if (mswiperefreshlayout.isrefreshing()) { mswiperefreshlayout.setrefreshing(false); } if(_userlist1.size() == 0){ viewgroup parentone = (viewgroup) viewone.getparent(); if(parentone != null){ parentone.removeview(viewone); } } if(_shipmentlist1.size() > 0 ){ mshipmentadapter = new shipmentadapter(getactivity(),_userlist1,1); shipmentlistview1.setadapter(mshipmentadapter); setlistviewheightbasedonchildren(shipmentlistview1); viewgroup parentone = (viewgroup) viewone.getparent(); if(parentone == null){ mainlayoutone.addview(viewone); } mshipmentadapter.notifydatasetchanged(); } mswiperefreshlayout.setclickable(true); } } }
please use fragmentstatepageradapter
that.
Comments
Post a Comment