/** Setup the viewpager for current and past trip lists */ private void setupViewPager() { FragmentManager fm = getSupportFragmentManager(); final ViewPager viewPager = (ViewPager) findViewById(R.id.pager); if (viewPager != null) { int tabPosition = PreferencesUtils.getInt( mActivity, R.string.feed_list_selected_key, PreferencesUtils.Tab.FEED_LIST_UPCOMING); FeedPagerAdapter adapter = new FeedPagerAdapter(fm); viewPager.setAdapter(adapter); viewPager.setPageTransformer(true, new ZoomOutSlideTransformer()); viewPager.setCurrentItem(tabPosition, true); TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs); tabLayout.setupWithViewPager(viewPager); tabLayout.setSmoothScrollingEnabled(true); tabLayout.setOnTabSelectedListener( new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { PreferencesUtils.setInt( mActivity, R.string.feed_list_selected_key, tab.getPosition()); viewPager.setCurrentItem(tab.getPosition(), true); } @Override public void onTabUnselected(TabLayout.Tab tab) {} @Override public void onTabReselected(TabLayout.Tab tab) { PreferencesUtils.setInt( mActivity, R.string.feed_list_selected_key, tab.getPosition()); } }); TabLayout.Tab tab = tabLayout.getTabAt(tabPosition); if (tab != null) { tab.select(); } } }