1

Am using ViewPager inside the Fragment class.In that ViewPager have three pages in each pages am show customized list view.ViewPager Some time shows the list view properly in some time it shows blank page.

Fragment class with ViewPager

public class Schedule extends Fragment{

RelativeLayout schedule_lay;
Schedule_fragment_adapter sfadp;
ViewPager pager;
TitlePageIndicator tpi;
PagerTabStrip pts;

@Override
public View onCreateView(LayoutInflater inflater,final ViewGroup container, Bundle savedInstanceState) {
    if (container == null) {
        return null;
    }

    schedule_lay = (RelativeLayout) inflater.inflate(R.layout.schedule, container, false);
    pager = (ViewPager) schedule_lay.findViewById(R.id.viewpager);
    pts = (PagerTabStrip)schedule_lay.findViewById(R.id.page_title_indicator);
    pts.setDrawFullUnderline(false);

    pts.setTextSize(TypedValue.COMPLEX_UNIT_SP, 22);
    pts.setTabIndicatorColor(Color.parseColor("#ff3824"));

    initialisePaging();

    return schedule_lay;
}

private void initialisePaging() {

    List<Fragment> fragments = new Vector<Fragment>();
    fragments.add(Fragment.instantiate(getActivity(), Ongoing.class.getName()));
    fragments.add(Fragment.instantiate(getActivity(), Upcoming.class.getName()));
    fragments.add(Fragment.instantiate(getActivity(), Recent.class.getName()));
    this.sfadp  = new Schedule_fragment_adapter(super.getActivity().getSupportFragmentManager(), fragments);

    pager.setAdapter(this.sfadp);
}
}

FragmentPagerAdapter

public class Schedule_fragment_adapter extends FragmentPagerAdapter {

private final List<Fragment> fragments;

/**
 * @param fm
 * @param fragments
 */
public Schedule_fragment_adapter(FragmentManager fm,
        List<Fragment> fragments) {
    super(fm);
    this.fragments = fragments;
}

@Override
public Fragment getItem(int position) {
    return this.fragments.get(position);
}

@Override
public int getCount() {
    return this.fragments.size();
}

@Override
public CharSequence getPageTitle(int position) {
    switch (position) {
    case 0:
        return "Ongoing";
    case 1:
        return "Upcoming";
    case 2:
        return "Recent";
    }
    return null;
}
}

Customized list view Class(My all three customized list class like below class )

 public class Ongoing extends Fragment{

RelativeLayout ongoing_lay;
ListView ongoing_matches_lv;
ArrayList<Item> ongoing_matches = new ArrayList<Item>();

@Override
public View onCreateView(LayoutInflater inflater,final ViewGroup container, Bundle savedInstanceState) {
    if (container == null) {
        return null;
    }

    ongoing_lay = (RelativeLayout) inflater.inflate(R.layout.ongoing, container, false);


    return ongoing_lay;
}
}

Am not able find out my issue.Can any one know help me to solve this issue.

Blo
  • 11,903
  • 5
  • 45
  • 99
Yugesh
  • 4,030
  • 9
  • 57
  • 97

1 Answers1

11

Use getChildFragmentManager() instead of super.getActivity().getSupportFragmentManager() when you instantiate the adapter at the line:

this.sfadp  = new Schedule_fragment_adapter(super.getActivity().getSupportFragmentManager(), fragments);
user
  • 86,916
  • 18
  • 197
  • 190
  • Thank you.Its Working fine.I have one more doubt.When i swipe this view pager.it was little bit slow.how can i improve it. – Yugesh Mar 28 '14 at 11:14
  • @Yugesh Either improve your layouts(to have fewer views and a shallow view hierarchy) or check if you're not doing any heavy initialization in the fragments that are used in the `ViewPager`. There isn't something obvious from the code you posted that would suggest something problematic. – user Mar 28 '14 at 11:19