I have a swipe tab with three different fragments for three tabs. getItem method in FragmentPagerAdapter called twice. My first tab loads local data and have different layout than next two tabs (tab2, tab3). Tab2 and Tab3 fetches data from server and load accordingly.
My problem is, for first time loading getItem called twice and this causes tab1 and tab2 both executed. Though tab1 only consist local data but because of twice calling tab2 executed and fetch data from server.
I don't want to execute tab2 and it's functionality while I'm in tab1 and so forth.
The getItem()
code:
@Override public Fragment getItem(int position) {
Fragment fragment = null;
switch (position) {
case 0: fragment = new CommentFragment(); break;
case 1: fragment = new AllPostFragment(); break;
case 2: fragment = new TodayFragment(); break;
}
return fragment;
}
So, I'm looking for a solution. Please help me out if you can.