Question

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.

Was it helpful?

Solution

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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top