Ejemplo n.º 1
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_viewpager, container, false);

    mAdapter = new TabPagerAdapter(getChildFragmentManager());

    mViewPager = (ViewPager) view.findViewById(R.id.viewpager);
    mViewPager.setAdapter(mAdapter);
    mViewPager.setPageMargin(getResources().getDimensionPixelSize(R.dimen.spacing_minor));

    mSlidingTabStrip = (SlidingTabLayout) view.findViewById(R.id.viewpager_tabs);
    mSlidingTabStrip.setViewPager(mViewPager);
    mSlidingTabStrip.setTabListener(
        new SlidingTabLayout.TabListener() {
          @Override
          public void onTabSelected(int pos) {
            // NO-OP
          }

          @Override
          public void onTabReSelected(int pos) {
            final Fragment fragment = mAdapter.getItem(pos);
            if (fragment instanceof ListFragment) {
              ((ListFragment) fragment).smoothScrollTo(0);
            }
          }
        });

    if (savedInstanceState != null) {
      mCurrentItem = savedInstanceState.getInt(SAVE_SELECTED_TAB);
    }

    return view;
  }
Ejemplo n.º 2
0
 @Override
 public void onResume() {
   super.onResume();
   mSlidingTabStrip.getBackground().setAlpha(255);
 }
Ejemplo n.º 3
0
 protected void setFragments(List<Fragment> fragments) {
   mAdapter.setFragments(fragments);
   mSlidingTabStrip.notifyDataSetChanged();
   mViewPager.setCurrentItem(mCurrentItem);
 }