java - SlidingTabLayout, Restarts fragment On case 4 to 1? -
my slidingtablayout restarts fragment dashboard activity when switching fragment tags fragment dashboard, or position 4 0. here code have written far, can shed light on situation ?
public class sectionspageradapter extends fragmentstatepageradapter { public sectionspageradapter(fragmentmanager fm) { super(fm); } @override public fragment getitem(int position) { //2 steps creating fragment, create fragment class , create ui fragment fragment = null; //we dont want return our place holder fragment instead want switch bewtween 3 //create switch case based on position applied or fragment selected switch (position) { case home: fragment = dashboard.newinstance("",""); break; case tags: fragment = tags.newinstance("",""); break; case my_recent: fragment = myposts.newinstance("",""); break; case top: fragment = top.newinstance("", ""); break; } return fragment; } @override public int getcount() { // show 3 total pages. return 4; } @override public charsequence getpagetitle(int position) { switch (position) { case 0: return "home"; case 1: return "top"; case 2: return "recent"; case 3: return "tags"; } return null; } }
you have load fragment in 1 time, should call method
int size=4; viewpager.setoffscreenpagelimit(size);
after set adapter, size no of fragment want load first time
Comments
Post a Comment