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.joncairo.android.todo.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // set up the main activity view to be populated with fragments.
    setContentView(R.layout.activity_main);

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

    // Create the adapter to manage tab switching
    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  .  co 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));
    }

    // Wire up the to do text entry field
    mNewToDoName = (EditText) findViewById(R.id.todo_text);
    mNewToDoName.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            DataLoader dataLoader = new DataLoader(getBaseContext(), mDataFileName);
            dataLoader.setTextInputData(s.toString());
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });

    // Wire up the to do enter button
    Button mDoIt = (Button) findViewById(R.id.enter_button);
    mDoIt.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ArrayList<Todo> mToDoToBeAdded = new ArrayList<Todo>();
            String newToDoText = setInputText();
            // Create a new todo instance 
            Todo newTodo = new Todo(newToDoText);
            mToDoToBeAdded.add(newTodo);
            // delete the text
            //mNewToDoName.setText("");
            // append it to the todolist array
            mtoDoFragment.addItemsToList(mToDoToBeAdded, "");
        }
    });
}

From source file:ch.bfh.instacircle.NetworkActiveActivity.java

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

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

    // Handle the change of the Wifi configuration
    wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    adhoc = new AdhocWifiManager(wifi);
    wifiapmanager = new WifiAPManager();
    registerReceiver(wifiReceiver, new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION));

    // Is NFC available on this device?
    nfcAvailable = this.getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC);

    // only set up the NFC stuff if NFC is also available
    if (nfcAvailable) {
        nfcAdapter = NfcAdapter.getDefaultAdapter(this);
        if (nfcAdapter.isEnabled()) {

            // Setting up a pending intent that is invoked when an NFC tag
            // is tapped on the back
            pendingIntent = PendingIntent.getActivity(this, 0,
                    new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);

            nfcIntentFilter = new IntentFilter();
            nfcIntentFilter.addAction(NfcAdapter.ACTION_NDEF_DISCOVERED);
            nfcIntentFilter.addAction(NfcAdapter.ACTION_TAG_DISCOVERED);
            intentFiltersArray = new IntentFilter[] { nfcIntentFilter };
        } else {
            nfcAvailable = false;
        }
    }
}

From source file:ca.psiphon.ploggy.ActivityMain.java

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

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

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

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

    // 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(mAppTabsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override/*from  w  w w .j a va  2 s . c  o  m*/
        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);
        }
    });

    actionBar.addTab(actionBar.newTab().setText(R.string.title_self_status_fragment).setTabListener(this));

    actionBar.addTab(actionBar.newTab().setText(R.string.title_friend_list_fragment).setTabListener(this));

    actionBar.addTab(actionBar.newTab().setText(R.string.title_message_list_fragment).setTabListener(this));
    mMessageListTabIndex = 2;

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

From source file:com.raypold.raypoldcounter.MainActivity.java

@Override
protected void onCreate(Bundle arg0) {

    super.onCreate(arg0);
    setContentView(R.layout.activity_main);

    context = getApplicationContext();/*from   w  w w. j  ava 2  s.  co m*/
    setFragmentManager();
    detectFirstRun();

    /*
     * Open the sharedPreference files for the actionBar functions extended
     * in ActionBarHandler
     */
    preferences = getSharedPreferences("userPreferences", 0);
    savedCounters = getSharedPreferences("savedCounters", 0);

    /* Create the action bar */
    final ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    viewPager = (ViewPager) findViewById(R.id.pager);
    viewPager.setAdapter(new FragmentAdapter(getSupportFragmentManager()));

    setTabNames();

    /* Create the navigation tabs and add them to the action bar */
    for (String tabName : tabNames) {
        actionBar.addTab(actionBar.newTab().setText(tabName).setTabListener(this));
    }

    /* Synchronize the the swiping and the highlighted tab view */
    viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageScrollStateChanged(int arg0) {
        }

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {
        }

        @Override
        public void onPageSelected(int arg0) {
            actionBar.setSelectedNavigationItem(arg0);
        }
    });
}

From source file:ru.lizaalert.common.ui.MainActivity.java

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

    // Set up the action bar.
    final ActionBar actionBar = getActionBar();
    assert actionBar != null;
    actionBar.setDisplayShowTitleEnabled(false);
    //   ?   , ? ?   ,  ? 
    //        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    mSectionsPagerAdapter = new SectionsPagerAdapter(this, getFragmentManager());

    Log.d("8800", "mViewPager " + mViewPager);
    Log.d("8800", "mSectionsPagerAdapter " + mSectionsPagerAdapter);
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override//from www  .  j  a v  a 2 s. c  o m
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
            if (position == 1) {
                if (getCurrentFocus() != null) {
                    InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(
                            INPUT_METHOD_SERVICE);
                    inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
                }
            }

        }
    });

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

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

    if (!Settings.instance(this).isLicenceAccepted()) {
        LicenceDialog licenceDialog = new LicenceDialog();
        licenceDialog.setListener(new LicenceDialog.Listener() {
            @Override
            public void onAcceptLicence(DialogInterface dialog) {
                dialog.dismiss();
                Settings.instance(MainActivity.this).setLicenceAccepted(true);
            }

            @Override
            public void onDeclineLicence(DialogInterface dialog) {
                dialog.dismiss();
                finish();
            }
        });
        licenceDialog.show(this);

    }
}

From source file:com.example.kaow.caltest.UserInfo.java

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

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

    final ActionBar actionBar = getActionBar();
    // Specify that the Home button should show an "Up" caret, indicating that touching the
    // button will take the user one step up in the application's hierarchy.
    actionBar.setDisplayHomeAsUpEnabled(true);

    // Set up the ViewPager, attaching the adapter and setting up a listener for when the
    // user swipes between sections.
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override/*from  w  ww . ja  v a  2s .  c  om*/
        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 < uInfoTitles.length; i++) {
        actionBar.addTab(actionBar.newTab().setText(uInfoTitles[i]).setTabListener(this));

    }
}

From source file:com.xortech.sender.SenderMain.java

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

    // REMOVE THE TITLE FROM THE ACTIONBAR
    getActionBar().setDisplayShowTitleEnabled(false);

    preferences = PreferenceManager.getDefaultSharedPreferences(this);

    mapType = preferences.getString("mapType", GMAPS);

    // CHECK FOR "DON'T KEEP ACTIVITIES" IN DEVELOPER OPTIONS
    boolean checkDeveloper = isAlwaysFinishActivitiesOptionEnabled();
    if (checkDeveloper) {
        showDeveloperOptionsScreen();//www . j  a  v a 2  s .c o m
    }

    /*
     * IF GOOGLE MAPS IS SELECTED AS THE DEFAULT, THEN CHECK TO
     * SEE IF THE USER HAS THE CORRECT VERSION OF GOOGLE PLAY SERVICES
     */
    if (mapType.equals(GMAPS)) {
        // GET GOOGLE PLAY STATUS
        int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);

        // CHECK IF GOOGLE PLAY SERVICE IS AVAILABLE 
        try {
            if (status != ConnectionResult.SUCCESS) {
                GooglePlayServicesUtil.getErrorDialog(status, this, RQS_GooglePlayServices).show();
            }
        } catch (Exception e) {
            Log.e("Error: GooglePlayServiceUtil: ", "" + e);
        }
    }

    // REGISTER A BROADCAST RECEIVER
    IntentFilter localIntentFilter = new IntentFilter("android.provider.Telephony.SMS_RECEIVED");
    localIntentFilter.setPriority(2147483646);
    mReceiver = new SmsReceiver();
    registerReceiver(mReceiver, localIntentFilter);

    try {
        // TRY TO LAUNCH APP RATER 
        AppRater.app_launched(this);
    } catch (Exception e) {
        Log.e("Error AppRater: ", "" + e);
    }

    // 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);

    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++) {

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

From source file:com.mstoyanov.music_lessons.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);//from  w  w w  . j a  v a2s.co  m
    final ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // if returning from an activity:
    if (getIntent().getStringExtra("WEEKDAY") != null) {
        weekday = getIntent().getStringExtra("WEEKDAY");
    }
    if (getIntent().getIntExtra("SELECTED_TAB", 0) != 0) {
        selectedTab = getIntent().getIntExtra("SELECTED_TAB", 0);
    }

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

    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            if (position == 6) {
                section = position; // "Students" tab
                actionBar.setSelectedNavigationItem(1);
            } else if (position == 7) {
                section = position; // "Add Student" tab
                actionBar.setSelectedNavigationItem(2);
            } else {
                section = position; // a schedule tab
                actionBar.setSelectedNavigationItem(0);
            }
        }
    });

    // Add tabs to the action bar:
    for (int i = 0; i < 3; i++) {
        actionBar
                .addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }

    actionBar.selectTab(actionBar.getTabAt(selectedTab));
}

From source file:com.example.kaow.caltest.MainFrag.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.frag_main);//from   w  w  w .  ja va  2 s  . c  om

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

    final ActionBar actionBar = getActionBar();
    // Specify that the Home button should show an "Up" caret, indicating that touching the
    // button will take the user one step up in the application's hierarchy.
    actionBar.setDisplayHomeAsUpEnabled(true);

    // Set up the ViewPager, attaching the adapter and setting up a listener for when the
    // user swipes between sections.
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager.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 each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mFoodTitles.length || i < mFoodIcon.length; i++) {
        actionBar.addTab(actionBar.newTab().setIcon(mFoodIcon[i]).setText(mFoodTitles[i]).setTabListener(this));

    }
}

From source file:com.cyanogenmod.settings.device.DeviceSettings.java

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

    mViewPager = new ViewPager(this);
    mViewPager.setId(R.id.viewPager);//from w  w w. j  av  a 2  s .  c  o  m
    setContentView(mViewPager);

    final ActionBar bar = getActionBar();
    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE, ActionBar.DISPLAY_SHOW_TITLE);
    bar.setTitle(R.string.app_name);

    mTabsAdapter = new TabsAdapter(this, mViewPager);
    mTabsAdapter.addTab(bar.newTab().setText(R.string.category_screen_title), ScreenFragmentActivity.class,
            null);
    mTabsAdapter.addTab(bar.newTab().setText(R.string.category_sensors_title), SensorsFragmentActivity.class,
            null);
    mTabsAdapter.addTab(bar.newTab().setText(R.string.category_haptic_title), HapticFragmentActivity.class,
            null);
    mTabsAdapter.addTab(bar.newTab().setText(R.string.category_storage_title), StorageFragmentActivity.class,
            null);
    mTabsAdapter.addTab(bar.newTab().setText(R.string.category_dock_title), DockFragmentActivity.class, null);

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