• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Delay showing content in Fragment Pager Adapter

I'm using FragmentPagerAdapter has 5 tabs. In tab number 3 I'm showing data in listview from web service and it showing successfully. When I swipe to tab 2, 4 and return to tab 3, the data is still showing in listview. If I swipe to tab 1, 5 and return to tab 3, the data delay to appearing some seconds.
* In TabFragment class I'm calling AsyncTask class called "GetTopNotifications". like this coding:
[HIGH]
public static class TabFragment extends Fragment
{
public static final String ARG_OBJECT = "object";

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
Bundle args = getArguments();
int position = args.getInt(ARG_OBJECT);

int tabLayout = 0;
switch (position)
{
case 0:
tabLayout = R.layout.tab1;
break;
case 1:
tabLayout = R.layout.tab2;
break;
case 2:
tabLayout = R.layout.tab3;
break;
case 3:
tabLayout = R.layout.tab4;
break;

}
View rootView = inflater.inflate(tabLayout, container, false);



if(position==0)
InitialTab1(rootView);
if(position==1)
InitialTab2(rootView);
if(position==2)
{
InitialTab3(rootView);
new GetTopNotifications(rootView);
}
if(position==3)
{
InitialTab4(rootView);
new GetTopMessages(rootView);
}



return rootView;
}
}[/HIGH]
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones