1

I have implemented Pager Sliding Strip and it is working totally fine.

I have 5 tabs each containing different fragment. When I click on 2nd tab to load respective fragment, it also load details of 3rd fragment, it showing the toast I coded in 3rd tab's fragment.

this is totally ruined the apps performance, How come I solve this problem I don't have any idea whats actually going on.

I am working on a really big project I cannot post the whole code.

Please Help me with this, I will post the respective code on demand.

Regards.

EDIT

Notification Fragment which is loading another fragment

    ListView notification_listview;
ArrayList<FragmentNotificationDTO> arraylist;
NotificationAdapter adapter;
private static View notificationView;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    if (notificationView != null) {
        ViewGroup parent = (ViewGroup) notificationView.getParent();
        if (parent != null)
            parent.removeView(notificationView);
    }
    notificationView = inflater.inflate(R.layout.fragment_notification,
            container, false);
    initLayout(notificationView);
    loadData();
    return notificationView;
}

private void initLayout(View view) {
    notification_listview = (ListView) view.findViewById(R.id.notification_listview);
    arraylist = new ArrayList<FragmentNotificationDTO>();
    adapter = new NotificationAdapter(mContext, arraylist);
    notification_listview.setAdapter(adapter);

}

This is Food Fragment which is loaded also when we click on Notification Tab

  private static View foodlistView;
RelativeLayout rl_foodshare, rl_foodrequested, rl_foodkitchen;
TextView tv_foodshare, tv_foodrequested, tv_foodkitchen;
ImageView img_foodshare, img_foodrequested, img_foodkitchen;
Fragment fr;
FragmentManager fm;
FragmentTransaction fragmentTransaction;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    if (foodlistView != null) {
        ViewGroup parent = (ViewGroup) foodlistView.getParent();
        if (parent != null)
            parent.removeView(foodlistView);
    }
    foodlistView = inflater.inflate(R.layout.fragment_location_list,
            container, false);
    initLayout(foodlistView);
    ChangeFragment(1);
    return foodlistView;
}

MainActivity.java which contains the PagerSlidingStrip & View Pager

 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
    viewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()));

    PagerSlidingTabStrip PGSTRIP = (PagerSlidingTabStrip) findViewById(R.id.tabs);
    PGSTRIP.setViewPager(viewPager);
    viewPager.setOffscreenPageLimit(0);
}
Asad Mehmood
  • 315
  • 1
  • 3
  • 20

1 Answers1

0

I solved my problem by overriding this method in each of my fragment and then calling the loading method when fragment's visibility is true to user.

    @Override
public void setUserVisibleHint(boolean isVisibleToUser) {
    super.setUserVisibleHint(isVisibleToUser);
    if (isVisibleToUser) {
        // load data here
    }else{
        // fragment is no longer visible
    }
}
Asad Mehmood
  • 315
  • 1
  • 3
  • 20