Example usage for android.app ActionBar setSelectedNavigationItem

List of usage examples for android.app ActionBar setSelectedNavigationItem

Introduction

In this page you can find the example usage for android.app ActionBar setSelectedNavigationItem.

Prototype

@Deprecated
public abstract void setSelectedNavigationItem(int position);

Source Link

Document

Set the selected navigation item in list or tabbed navigation modes.

Usage

From source file:com.piusvelte.mosaic.android.Main.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);/*  w  w  w  .  ja v  a2s  .  co  m*/

    pagerAdapter = new MosaicPagerAdapter(getSupportFragmentManager());

    final ActionBar actionBar = getActionBar();
    //        actionBar.setHomeButtonEnabled(false);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    viewPager = (ViewPager) findViewById(R.id.pager);
    viewPager.setAdapter(pagerAdapter);
    viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            // When swiping between different app sections, select the corresponding tab.
            // We can also use ActionBar.Tab#select() to do this if we have a reference to the
            // Tab.
            actionBar.setSelectedNavigationItem(position);
        }
    });
    for (int i = 0; i < pagerAdapter.getCount(); i++) {
        // Create a tab with text corresponding to the page title defined by the adapter.
        // Also specify this Activity object, which implements the TabListener interface, as the
        // listener for when this tab is selected.
        actionBar.addTab(actionBar.newTab().setText(pagerAdapter.getPageTitle(i)).setTabListener(this));
    }
}

From source file:eu.chainfire.geolog.ui.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    final ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override//from   w w  w  .  ja  v a2  s . c om
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
            invalidateOptionsMenu();
        }
    });
    mViewPager.setOffscreenPageLimit(3);

    for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
        actionBar
                .addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }

    int play = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
    if (play == ConnectionResult.SUCCESS) {
        // Force database creation
        Database.Helper helper = Database.Helper.getInstance(this);
        helper.getReadableDatabase();

        // Force Off profile as default
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        long id = prefs.getLong(SettingsFragment.PREF_CURRENT_PROFILE, 0);
        Database.Profile profile = Database.Profile.getById(helper, id, null);
        if (profile == null)
            id = 0;
        if (id == 0) {
            profile = Database.Profile.getOffProfile(helper);
            id = profile.getId();
            prefs.edit().putLong(SettingsFragment.PREF_CURRENT_PROFILE, id).commit();
        }

        // Start background service
        if (profile.getType() != Database.Profile.Type.OFF)
            BackgroundService.startService(this);
    } else {
        GooglePlayServicesUtil.getErrorDialog(play, this, 0).show();
        finish();
    }
}

From source file:com.hybris.mobile.activity.LoginActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_login);
    mViewPager = (ViewPager) findViewById(R.id.pager);
    Fragment[] frags = { new LoginFragment(), new RegistrationFragment() };
    FragmentPagerAdapter adapter = new TabsAdapter(getFragmentManager(), frags);
    mViewPager.setAdapter(adapter);/*  w  ww  .ja  v  a 2  s . c  o m*/
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            getActionBar().setSelectedNavigationItem(position);
        }
    });

    ActionBar actionBar = getActionBar();
    actionBar.setHomeButtonEnabled(true);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    MyTabListener tabListener = new MyTabListener(mViewPager, actionBar);
    Tab tab = actionBar.newTab().setText(R.string.tab_login).setTabListener(tabListener);
    actionBar.addTab(tab);

    tab = actionBar.newTab().setText(R.string.tab_register).setTabListener(tabListener);
    actionBar.addTab(tab);
    actionBar.setSelectedNavigationItem(0);

    // Handler to handle different asynchronous cases:
    // - When the user arrives from the scanning activity and scan a barcode that needs the user to be logged in, 
    mHandler = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
            // Error retrieving the data of the scanned value, we finish the activity and display a error message
            case BarCodeScannerActivity.MSG_DATA_ERROR:
                showMessage((String) msg.obj);
                finish();
                break;

            // Data available, we can start the activity associated with the intent
            case BarCodeScannerActivity.MSG_DATA_AVAILABLE:
                if (mIntentBarcodeAfterLogin != null) {
                    mIntentBarcodeAfterLogin.startActivity();
                    finish();
                }
                break;

            }

        }

    };

}

From source file:com.example.android.supportv13.app.FragmentNestingPagerSupport.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mViewPager = new ViewPager(this);
    mViewPager.setId(R.id.pager);//w  ww .  j  a  v  a2  s  . c o m
    setContentView(mViewPager);

    final ActionBar bar = getActionBar();
    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    bar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);

    mTabsAdapter = new TabsAdapter(this, mViewPager);
    mTabsAdapter.addTab(bar.newTab().setText("Simple"), CountingFragment.class, null);
    mTabsAdapter.addTab(bar.newTab().setText("List"), FragmentPagerSupport.ArrayListFragment.class, null);
    mTabsAdapter.addTab(bar.newTab().setText("Cursor"), CursorFragment.class, null);
    mTabsAdapter.addTab(bar.newTab().setText("Tabs"), FragmentTabsFragment.class, null);

    if (savedInstanceState != null) {
        bar.setSelectedNavigationItem(savedInstanceState.getInt("tab", 0));
    }
}

From source file:com.tesfayeabel.lolchat.ui.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_lolchat_main);
    viewPager = (ViewPager) findViewById(R.id.pager);
    final ActionBar actionBar = getActionBar();
    ArrayList<LOLChatFragment> fragments = new ArrayList<LOLChatFragment>();
    fragments.add(new MainFragment());
    fragments.add(new ConversationsFragment());
    fragments.add(new SummonerSearchFragment());
    viewPager.setOffscreenPageLimit(fragments.size() - 1);
    viewPager.setAdapter(new FragmentPagerAdapter(getFragmentManager(), fragments));
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override/* w w w. j a va2  s . co  m*/
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
            FragmentPagerAdapter adapter = (FragmentPagerAdapter) viewPager.getAdapter();
            if (getLolChat() != null)
                adapter.getRegisteredFragment(position).onChatConnected(getLolChat());
        }

        @Override
        public void onPageScrolled(int i, float f, int f1) {
        }

        @Override
        public void onPageScrollStateChanged(int i) {
        }
    });
    ActionBar.TabListener tl = new ActionBar.TabListener() {
        @Override
        public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
            viewPager.setCurrentItem(tab.getPosition());
        }

        @Override
        public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
        }

        @Override
        public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
        }
    };
    actionBar.addTab(actionBar.newTab().setIcon(R.drawable.lolchat_friend).setTabListener(tl));
    actionBar.addTab(actionBar.newTab().setIcon(R.drawable.lolchat_recent).setTabListener(tl));
    actionBar.addTab(actionBar.newTab().setIcon(R.drawable.lolchat_search).setTabListener(tl));
}

From source file:pack_generic.Act_NPS.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mViewPager = new ViewPager(this);
    mViewPager.setId(R.id.pager);/*w w w  .j av  a 2 s  .com*/
    setContentView(mViewPager);

    final ActionBar bar = getActionBar();
    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    bar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);

    mTabsAdapter = new TabsAdapter(this, mViewPager);
    mTabsAdapter.addTab(bar.newTab().setText("Frag_Page"), Frag_Page.class, null);
    mTabsAdapter.addTab(bar.newTab().setText("Fish list"), Act_ButtonList_Fish.ArrayListFragment.class, null);
    mTabsAdapter.addTab(bar.newTab().setText("Frag_List_Contacts"), Frag_List_Contacts.class, null);
    mTabsAdapter.addTab(bar.newTab().setText("Frag_Tabs"), Frag_Tabs.class, null);

    if (savedInstanceState != null) {
        bar.setSelectedNavigationItem(savedInstanceState.getInt("tab", 0));
    }
}

From source file:com.stockbrowser.ComboViewActivity.java

@TargetApi(14)
@Override//w w  w .j ava2  s  .  co  m
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setResult(RESULT_CANCELED);
    Bundle extras = getIntent().getExtras();
    Bundle args = extras.getBundle(EXTRA_COMBO_ARGS);
    // 
    //        String svStr = extras.getString(EXTRA_INITIAL_VIEW, null);
    String svStr = extras.getString(EXTRA_INITIAL_VIEW);
    UI.ComboViews startingView = svStr != null ? UI.ComboViews.valueOf(svStr) : UI.ComboViews.Bookmarks;
    mViewPager = new ViewPager(this);
    mViewPager.setId(R.id.tab_view);
    setContentView(mViewPager);

    final ActionBar bar = getActionBar();
    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    if (BrowserActivity.isTablet(this)) {
        bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_USE_LOGO);
        bar.setHomeButtonEnabled(true);
    } else {
        bar.setDisplayOptions(0);
    }

    mTabsAdapter = new TabsAdapter(this, mViewPager);
    mTabsAdapter.addTab(bar.newTab().setText(R.string.tab_bookmarks), BrowserBookmarksPage.class, args);

    if (savedInstanceState != null) {
        bar.setSelectedNavigationItem(savedInstanceState.getInt(STATE_SELECTED_TAB, 0));
    } else {
        switch (startingView) {
        case Bookmarks:
            mViewPager.setCurrentItem(0);
            break;
        case History:
            mViewPager.setCurrentItem(1);
            break;
        case Snapshots:
            mViewPager.setCurrentItem(2);
            break;
        }
    }
}

From source file:com.lj.fileexplorer.FileExplorerTabActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.fragment_pager);
    mViewPager = (ViewPager) findViewById(R.id.pager);
    //????/* www. ja v a 2 s  .  c o m*/
    mViewPager.setOffscreenPageLimit(DEFAULT_OFFSCREEN_PAGES);

    final ActionBar bar = getActionBar();
    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    bar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_HOME);

    mTabsAdapter = new TabsAdapter(this, mViewPager);
    mTabsAdapter.addTab(bar.newTab().setText(R.string.tab_category), FileCategoryActivity.class, null);
    mTabsAdapter.addTab(bar.newTab().setText(R.string.tab_sd), FileViewActivity.class, null);
    mTabsAdapter.addTab(bar.newTab().setText(R.string.tab_remote), ServerControlActivity.class, null);

    //
    bar.setSelectedNavigationItem(PreferenceManager.getDefaultSharedPreferences(this).getInt(INSTANCESTATE_TAB,
            Util.CATEGORY_TAB_INDEX));
}

From source file:com.androiduipatterns.smashingandroidui.examples.tabs.TabsExampleActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tabs_example);
    // Create the adapter that will return a fragment for each of the three primary sections
    // of the app.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    // Set up the action bar.
    final ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    // When swiping between different sections, select the corresponding tab.
    // We can also use ActionBar.Tab#select() to do this if we have a reference to the
    // Tab./* w ww .ja va 2s  .  c  o  m*/
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }
    });

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
        // Create a tab with text corresponding to the page title defined by the adapter.
        // Also specify this Activity object, which implements the TabListener interface, as the
        // listener for when this tab is selected.
        actionBar
                .addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }
}

From source file:cmpe.alpha.fitwhiz.sensortag.ViewPagerActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    // Log.d(TAG, "onCreate");
    super.onCreate(savedInstanceState);
    setContentView(mResourceFragmentPager);

    // Set up the action bar
    final ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    ImageView view = (ImageView) findViewById(android.R.id.home);
    view.setPadding(10, 0, 20, 10);//from   ww  w .  j a  v a2 s  .c o  m

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(mResourceIdPager);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int n) {
            // Log.d(TAG, "onPageSelected: " + n);
            actionBar.setSelectedNavigationItem(n);
        }
    });
    // Create the adapter that will return a fragment for each section
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager.setAdapter(mSectionsPagerAdapter);
}