1

I am using Holoeverywhere and ViewPagerIndicator; using Holoeverywhere1 I implemented the slider and tabs in the Fragment using ViewPagerIndicator. Everything is working fine, Slider working, the menu in it, the tabs; the tabs works fine only the first time, when I move to other Fragment using the slider and come back to the tabs Fragment, the contents are no more available.

Code for the Fragment where tabs are created

public class SeconFrag extends Fragment {

    ViewPager mViewPager;
    FragmentAdapter mTabsAdapter;
    PageIndicator mIndicator;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        mTabsAdapter = new FragmentAdapter(getSupportFragmentManager());


        View view = inflater.inflate(R.layout.second_frag);
        mViewPager = (ViewPager) view.findViewById(R.id.pager);
        mViewPager.setAdapter(mTabsAdapter);



        TitlePageIndicator indicator = (TitlePageIndicator) view
                .findViewById(R.id.indicator);
        indicator.setViewPager(mViewPager);
        indicator.setFooterIndicatorStyle(IndicatorStyle.Triangle);
        mIndicator = indicator;

        return view;
    }

    @Override
    public void onResume() {
        super.onResume();
        getSupportActionBar().setSubtitle("Create");

    }


}

FragmentAdapter code

public class FragmentAdapter extends FragmentPagerAdapter{
    protected static final String[] CONTENT = new String[] { "Choose", "Customise" };

    private int mCount = CONTENT.length;

    public FragmentAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int position) {
        if (position == 0) {
            return  TabOne.newInstance();
        } else if (position == 1) {
            return  TabTwo.newInstance();
        }else if (position == 3 ) {
            return  TabOne.newInstance();
        }else 
            return  null;

    }

    @Override
    public int getCount() {
        return mCount;
    }

    @Override
    public CharSequence getPageTitle(int position) {
      return FragmentAdapter.CONTENT[position % CONTENT.length];
    }

    public void setCount(int count) {
        if (count > 0 && count <= 10) {
            mCount = count;
            notifyDataSetChanged();
        }
    }
}

on of the tab Fragment

public final class TabOne extends Fragment {

    public static TabOne newInstance() {
        TabOne fragment = new TabOne();
        return fragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View myFragmentView = inflater.inflate(R.layout.tab_one, container,
                false);
        return myFragmentView;
    }
}

in the SeconFrag OnPause() I removed the Fragment no luck, hide() it in the OnPause() and tried to show() in the OnResume() still not showing content after the Fragment is changed.

EDIT

First time opening the fragment Change Fragment using slider Contents gone

Atif Farrukh
  • 2,219
  • 2
  • 25
  • 47

0 Answers0