Example usage for android.support.v4.app ActionBar selectTab

List of usage examples for android.support.v4.app ActionBar selectTab

Introduction

In this page you can find the example usage for android.support.v4.app ActionBar selectTab.

Prototype

public abstract void selectTab(ActionBar.Tab tab);

Source Link

Document

Select the specified tab.

Usage

From source file:com.actionbarsherlock.sample.hcgallery.MainActivity.java

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

    if (savedInstanceState != null && savedInstanceState.getInt("theme", -1) != -1) {
        mThemeId = savedInstanceState.getInt("theme");
        this.setTheme(mThemeId);
    }/*from  w  w w .ja va2  s.co  m*/

    setContentView(R.layout.main);

    Directory.initializeDirectory();

    ActionBar bar = getSupportActionBar();

    int i;
    for (i = 0; i < Directory.getCategoryCount(); i++) {
        bar.addTab(bar.newTab().setText(Directory.getCategory(i).getName()).setTabListener(this));
    }

    mActionBarView = getLayoutInflater().inflate(R.layout.action_bar_custom, null);

    bar.setCustomView(mActionBarView);
    bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_USE_LOGO);
    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    bar.setDisplayShowHomeEnabled(true);

    // If category is not saved to the savedInstanceState,
    // 0 is returned by default.
    if (savedInstanceState != null) {
        int category = savedInstanceState.getInt("category");
        bar.selectTab(bar.getTabAt(category));
    }
}

From source file:com.abcvoipsip.ui.SipHome.java

private void selectTabWithAction(Intent intent) {
    if (intent != null) {
        String callAction = intent.getAction();
        if (!TextUtils.isEmpty(callAction)) {
            ActionBar ab = getSupportActionBar();
            Tab toSelectTab = null;//from  www .  j a  v  a2  s . c  o m
            if (callAction.equalsIgnoreCase(SipManager.ACTION_SIP_DIALER)) {
                toSelectTab = ab.getTabAt(TAB_INDEX_DIALER);
            } else if (callAction.equalsIgnoreCase(SipManager.ACTION_SIP_CALLLOG)) {
                toSelectTab = ab.getTabAt(TAB_INDEX_CALL_LOG);
            } else if (callAction.equalsIgnoreCase(SipManager.ACTION_SIP_MESSAGES)) {
                toSelectTab = ab.getTabAt(TAB_INDEX_MESSAGES);
            }
            if (toSelectTab != null) {
                ab.selectTab(toSelectTab);
            }
        }
    }
}