android - Reusing ListFragment with ViewPager -
i have 7 tabs , shared fragment data depends on xml received url. problem if set setoffscreenpagelimit(6) , first tab, fine tab number 1 tab number 2 7 shows data url supposed show in last tab.
viewpager = (viewpager) findviewbyid(r.id.pager); actionbar = getactionbar(); madapter = new tabspageradapter(getsupportfragmentmanager(), this, negeri); viewpager.setadapter(madapter); viewpager.setoffscreenpagelimit(6); actionbar.sethomebuttonenabled(true); actionbar.setdisplayhomeasupenabled(true); actionbar.settitle("list"); actionbar.setnavigationmode(actionbar.navigation_mode_tabs); // adding tabs (string tab_name : tabs) { actionbar.addtab(actionbar.newtab().settext(tab_name) .settablistener(this)); } /** * on swiping viewpager make respective tab selected * */ viewpager.setonpagechangelistener(new viewpager.onpagechangelistener() { @override public void onpageselected(int position) { // on changing page // make respected tab selected actionbar.setselectednavigationitem(position); } @override public void onpagescrolled(int arg0, float arg1, int arg2) { } @override public void onpagescrollstatechanged(int arg0) { } });
fragmentstatepageradapter;
public class tabspageradapter extends fragmentstatepageradapter { static context context; static resources res = null; static string[] content = null; public tabspageradapter(fragmentmanager fm, context c, string negeri) { super(fm); context = c; res = context.getresources(); content = res.getstringarray(r.array.values); } @override public listfragment getitem(int index) { return daerahfragment.newinstance(content[index]); } @override public int getcount() { // item count - equal number of tabs return content.length; } public int getitemposition(object object) { return position_none; }
}
listfragment;
public static listfragment newinstance(string daerahval) { // todo auto-generated method stub bundle args = new bundle(); args.putstring(arg_daerah, daerahval); daerahfragment fragment = new daerahfragment(); fragment.setarguments(args); return fragment; } @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); // bundle args = getarguments(); //string daerah=args.getstring("daerah"); daerah = getarguments().getstring(arg_daerah); toast.maketext(getactivity(), "daerah= " + daerah , toast.length_short).show(); url = "http://www.url.com/android/daerahmarker.php?daerah="+daerah; setretaininstance(true); if (mlistviewscrollpos != null && adapter != null) { getlistview().onrestoreinstancestate(mlistviewscrollpos); } else { mytask = new talktoserver(); mytask.execute(); } }
tq
i solved this
just remove static
static string url = "";
to
string url = "";
:)
Comments
Post a Comment