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:de.toshsoft.tsremote.configuration.ConfigurationActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    // Remove all StandOut Windows
    StandOutWindow.closeAll(this, StandOutRemoteActivity.class);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.configuration_activity);

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

    // 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 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.
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override//  www  .  j ava2  s .c  o m
        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 callback (listener) for when
        // this tab is selected.
        actionBar
                .addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }
}

From source file:com.yuya.routerecorder.FragmentTabs.java

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

    instance = this;

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

    //bar.setDisplayShowTitleEnabled(false);
    //bar.setDisplayShowHomeEnabled(false);
    bar.setDisplayShowCustomEnabled(false);

    bar.addTab(bar.newTab().setIcon(R.drawable.world_white)
            .setTabListener(new TabListener<RouteMapFragment>(this, "Show Map", RouteMapFragment.class)));

    bar.addTab(bar.newTab().setIcon(R.drawable.pen_white_frame)
            .setTabListener(new TabListener<AddRouteFragment>(this, "Add Trip", AddRouteFragment.class)));

    bar.addTab(bar.newTab().setIcon(R.drawable.list_new)
            .setTabListener(new TabListener<MyListFragment>(this, "Show List", MyListFragment.class)));

    if (savedInstanceState != null) {
        bar.setSelectedNavigationItem(savedInstanceState.getInt("tab", 0));
    }/*from   w ww.ja  v  a  2  s .  c  o  m*/

    //FragmentManager manager = getSupportFragmentManager();
    //fragmentA = (RouteMapFragment) manager.findFragmentById(R.id.map);
    //fragmentB = (AddRouteFragment) manager.findFragmentById(R.id.fragment_container);

}

From source file:com.Candy.center.CandyCenter.java

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

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

    // 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 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.
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override//  w  w w. j  a v a 2  s . com
        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 callback (listener) for when
        // this tab is selected.
        actionBar
                .addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }
}

From source file:org.ounl.lifelonglearninghub.nfcecology.swipe.SwipeActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_swipe);

    // Create the adapter that will return a fragment for each of the three
    // primary sections
    // of the app.
    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager());

    // Set up the action bar.
    final ActionBar actionBar = getActionBar();
    actionBar.setHomeButtonEnabled(true);

    // Specify that we will be displaying tabs in the action bar.
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Set up the ViewPager, attaching the adapter and setting up a listener
    // for when the
    // user swipes between sections.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override/*from   w w  w. ja v  a 2 s.com*/
        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 each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mAppSectionsPagerAdapter.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(mAppSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }

}

From source file:au.com.runecasters.volumescheduler.app.RuleActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_rule);
    mButtonCreateRule = (Button) findViewById(R.id.buttonCreateRule);

    mSchedulerRule = getIntent().getParcelableExtra("existingRule");
    if (mSchedulerRule == null) {
        mSchedulerRule = new SchedulerRule(getIntent().getIntExtra("selector", -1));
        mNewRule = true;/*from   w  ww . j  a  v  a2 s  . c o  m*/
    }

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

    // Create the adapter that will return a fragment for each of the three
    // primary sections of the activity.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager());

    // 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.
    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 callback (listener) for when
        // this tab is selected.
        actionBar
                .addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }

    mButtonCreateRule.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
                ScheduleRuleSetter ruleFragment = (ScheduleRuleSetter) mSectionsPagerAdapter.getItem(i);
                ruleFragment.setRules(mSchedulerRule);
            }
            DatabaseHelper dbHelper = DatabaseHelper.getInstance(RuleActivity.this);
            if (mNewRule) {
                dbHelper.addRule(mSchedulerRule);
            } else {
                dbHelper.updateRule(mSchedulerRule);
            }
            setResult(RESULT_OK);
            finish();
        }
    });
}

From source file:com.gieseckedevrient.android.pcscdroid.MainActivity.java

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

    appContext = getApplicationContext();

    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

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

    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);
    mViewPager.setOffscreenPageLimit(2);

    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override//  ww  w. j  a  va2  s. c o m
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }
    });

    for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {

        actionBar
                .addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }
}

From source file:com.norman0406.slimgress.ActivityOps.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_ops);

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

    // 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 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.
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override//from   w ww  .  j a  va 2s . com
        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 callback (listener) for when
        // this tab is selected.
        actionBar
                .addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }
}

From source file:com.michellgaby.advsettings.DeviceSettings.java

@TargetApi(11)
@Override/*from ww w.  ja va2 s. c  om*/
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mViewPager = new ViewPager(this);
    mViewPager.setId(R.id.viewPager);
    setContentView(mViewPager);

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

    // Remove title and icon
    bar.setDisplayShowHomeEnabled(false);
    bar.setDisplayShowTitleEnabled(false);

    mTabsAdapter = new TabsAdapter(this, mViewPager);
    mTabsAdapter.addTab(bar.newTab().setText(R.string.general_settings_title), GeneralSettings.class, null);
    /**
     * mTabsAdapter.addTab(
     * bar.newTab().setText(R.string.category_mdnie_title),
     * mDNIeFragmentActivity.class, null); mTabsAdapter.addTab(
     * bar.newTab().setText(R.string.category_sensors_title),
     * SensorsFragmentActivity.class, null);
     */

    mTabsAdapter.addTab(bar.newTab().setText(R.string.system_settings_title), SystemSettings.class, null);

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

From source file:net.seedboxer.seedroid.activities.MainActivity.java

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

    setContentView(R.layout.main_activity_view);

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

    // Specify that the Home/Up button should not be enabled, since there is no hierarchical
    // parent.//from   ww  w.ja va  2  s .  co m
    actionBar.setHomeButtonEnabled(false);

    // Specify that we will be displaying tabs in the action bar.
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    mViewPager = (ViewPager) findViewById(R.id.pager);

    mAppSectionsPagerAdapter = new TabsAdapter(this, getSupportFragmentManager(), mViewPager);
    mAppSectionsPagerAdapter.addTab(actionBar.newTab().setText(R.string.tab_title_inprogres),
            StatusFragment.class, null);
    mAppSectionsPagerAdapter.addTab(actionBar.newTab().setText(R.string.tab_title_queue), InQueueFragment.class,
            null);
    mAppSectionsPagerAdapter.addTab(actionBar.newTab().setText(R.string.tab_title_downloads),
            DownloadsFragment.class, null);

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

    GCMRegistrar.checkManifest(this);
    GCMRegistrar.checkDevice(this);
}

From source file:com.mac.SafeWalk.WelcomeActivity.java

/**
 * Called when the activity is first created.
 *//* w w w .  j ava2  s  .  com*/
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.welcome_screen);
    // Create adapter
    collectionPagerAdapter = new CollectionPagerAdapter(getSupportFragmentManager());

    // Set up action bar.
    final ActionBar actionBar = getActionBar();
    actionBar.hide();

    // Specify that the Home/Up button should not be enabled, since there is no hierarchical parent.
    actionBar.setHomeButtonEnabled(false);

    // Specify that we will be displaying tabs in the action bar.
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Set up the ViewPager
    // Attache the adapter and implement listener in order to respond when user swipes between sections.
    viewPager = (ViewPager) findViewById(R.id.pager);
    viewPager.setAdapter(collectionPagerAdapter);
    viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            // Select the corresponding tab when user swipes
            actionBar.setSelectedNavigationItem(position);
            ImageView dot1 = (ImageView) findViewById(R.id.sliding_dot1);
            ImageView dot2 = (ImageView) findViewById(R.id.sliding_dot2);
            switch (position) {
            case 0:
                animate(dot1);
                break;
            case 1:
                animate(dot2);
                break;
            case 2:
                break;
            }
        }
    });
    // For each of the sections, add tab to the action bar.
    for (int i = 0; i < collectionPagerAdapter.getCount(); i++) {
        // Create tabs
        actionBar.addTab(actionBar.newTab().setTabListener(this));
    }
    Settings.getSettings().setContext(this);
}