@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); setTitle(); ActionBar.Tab reportsTab = getSupportActionBar().newTab().setText(getString(R.string.reports)); ActionBar.Tab mapTab = getSupportActionBar().newTab().setText(getString(R.string.map)); mViewPager = (ReportViewPager) findViewById(R.id.pager); mTabsAdapter = new TabsAdapter(this, getSupportActionBar(), mViewPager); mTabsAdapter.addTab(reportsTab, ListReportFragment.class); mTabsAdapter.addTab(mapTab, MapFragment.class); if (savedInstanceState != null) { getSupportActionBar().setSelectedNavigationItem(savedInstanceState.getInt("index")); } }
@Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putInt("index", getSupportActionBar().getSelectedNavigationIndex()); }