Example usage for android.app ActionBar addTab

List of usage examples for android.app ActionBar addTab

Introduction

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

Prototype

@Deprecated
public abstract void addTab(Tab tab);

Source Link

Document

Add a tab for use in tabbed navigation mode.

Usage

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/*from  w  ww  .j  a va2s  .  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.wbrenna.gtfsoffline.MainActivity.java

@Override
protected void onResume() {
    super.onResume();

    //we want to refresh the databases list
    Set<String> emptyString = new HashSet<String>();
    emptyString.clear();/*from  w w w . ja va 2s  . c o  m*/

    Set<String> initial_preferences = mPrefs.getStringSet(getString(R.string.pref_dbs), emptyString);

    //in case we're on a low-ram system and things aren't cached
    try {
        if (!initial_preferences.equals(mDBListPrefsOld)) {

            mDBListPrefsOld = initial_preferences;
            //this is the list of currently checked databases
            mDBActive = null;
            //just to nullify the previous one.
            if (initial_preferences.size() != 0) {
                String[] tmpDBActive = initial_preferences.toArray(new String[initial_preferences.size()]);
                dbHelper.gatherFiles();
                mDBList = dbHelper.GetListofDB();
                List<String> workingDBList = new ArrayList<String>();

                for (int i = 0; i < tmpDBActive.length; i++) {
                    if (mDBList.contains(tmpDBActive[i])) {
                        workingDBList.add(tmpDBActive[i]);
                    }
                }
                if (workingDBList.size() == 0) {
                    mDBActive = null;
                } else {
                    mDBActive = workingDBList.toArray(new String[workingDBList.size()]);
                }
            }

            mSectionsPagerAdapter.notifyDataSetChanged();

            //totally kill the viewPager and all, and recreate!
            //mSectionsPagerAdapter = null;
            //getFragmentManager().beginTransaction().replace(containerViewId, fragment);
            //and create the appropriate tabs
            final ActionBar actionBar = getActionBar();

            /**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);
             }
                  });**/
            if (actionBar != null) {
                actionBar.removeAllTabs();
            }
            for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
                actionBar.addTab(
                        actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));

                //update the fragment contents
                /**if (i > 0 ) {
                   Fragment newFragment = new DBListFragment();
                   Bundle args = new Bundle();
                   args.putString(DBListFragment.DATABASE, mDBActive[i-1]);
                   newFragment.setArguments(args);
                           
                   getFragmentManager().beginTransaction().replace(i, newFragment);
                }**/
                if (i > 0) {
                    DBListFragment aFragment = (DBListFragment) getSupportFragmentManager()
                            .findFragmentByTag("android:switcher:" + R.id.pager + ":" + Integer.toString(i));
                    if (aFragment != null) {
                        getSupportFragmentManager().beginTransaction().remove(aFragment).commit();
                        mSectionsPagerAdapter.notifyDataSetChanged();
                        //if (aFragment.getView() != null) {
                        //aFragment.updateDisplay();
                        //}

                    }
                } else if (i == 0) {
                    FavSectionFragment aFavFragment = (FavSectionFragment) getSupportFragmentManager()
                            .findFragmentByTag("android:switcher:" + R.id.pager + ":" + Integer.toString(i));
                    if (aFavFragment != null) {
                        //getSupportFragmentManager().beginTransaction().remove(aFavFragment).commit();
                        //mSectionsPagerAdapter.notifyDataSetChanged();
                        //if (aFavFragment.getView() != null) {
                        //aFavFragment.updateDisplay();

                        //}
                        aFavFragment.updatePositions();

                    }
                }

            }
        }
    } finally {

        //restart location manager
        //mLocationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
        mLocationHelper.refresh(locationListener);
    }

}

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// w ww. java  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);
        }
    });

    // 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  . co  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.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 ww  w .  j  a va2s  .c om*/
        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.shinobicontrols.transitions.StoryDetailActivity.java

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

    if (savedInstanceState == null) {
        // Load the data from the intent on first pass
        Intent intent = getIntent();//  w  w  w  . j  a  va  2s.  c  o m
        String story_id = intent.getStringExtra(ARG_STORY_ID);
        mItem = StoryContent.STORY_MAP.get(story_id);
    }

    // Get hold of some relevant content
    final ViewGroup container = (ViewGroup) findViewById(R.id.container);

    // What are the layouts we should be able to transition between
    List<Integer> sceneLayouts = Arrays.asList(R.layout.content_scene_00, R.layout.content_scene_01,
            R.layout.content_scene_02);
    // Create the scenes
    sceneList = new ArrayList<Scene>();
    for (int layout : sceneLayouts) {
        // Create the scene
        Scene scene = Scene.getSceneForLayout(container, layout, this);
        // Just before the transition starts, ensure that the content has been loaded
        scene.setEnterAction(new Runnable() {
            @Override
            public void run() {
                addContentToViewGroup(container);
            }
        });
        // Save the scene into
        sceneList.add(scene);
    }

    // Build the transition manager
    TransitionInflater transitionInflater = TransitionInflater.from(this);
    mTransitionManager = transitionInflater.inflateTransitionManager(R.transition.story_transition_manager,
            container);

    // Show the Up button in the action bar.
    final ActionBar actionBar = getActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);

        // Specify we want some tabs
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

        // Create a listener to cope with tab changes
        ActionBar.TabListener tabListener = new ActionBar.TabListener() {
            @Override
            public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
                // If there's a scene for this tab index, then transition to it
                if (tab.getPosition() <= sceneList.size()) {
                    performTransitionToScene(sceneList.get(tab.getPosition()));
                }
            }

            @Override
            public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
                // Can ignore this event
            }

            @Override
            public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
                // Can ignore this event
            }

            private void performTransitionToScene(Scene scene) {
                mTransitionManager.transitionTo(scene);
            }
        };

        // Add some tabs
        for (int i = 0; i < sceneList.size(); i++) {
            actionBar.addTab(actionBar.newTab().setText("Scene " + i).setTabListener(tabListener));
        }
    }

    // Load the first scene
    sceneList.get(0).enter();
}

From source file:app.sunstreak.yourpisd.MainActivity.java

private void setUpTabs() {
    final ActionBar actionBar = getActionBar();

    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    actionBar.addTab(actionBar.newTab().setText(getResources().getString(R.string.main_section_0_title))
            .setTabListener(this));
    actionBar.addTab(/*from   w  ww .j  a v  a 2 s  . c  o m*/
            actionBar.newTab().setText(TermFinder.Term.values()[CURRENT_TERM_INDEX].name).setTabListener(this));
    actionBar.addTab(actionBar.newTab().setText(getResources().getString(R.string.main_section_2_title))
            .setTabListener(this));
    // actionBar.addTab(actionBar.newTab().setText(getResources().getString(R.string.main_section_3_title))
    // .setTabListener(this));
    //        mViewPager
    //                .setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
    //                    @Override
    //                    public void onPageSelected(int position) {
    //                        // on changing the page
    //                        // make respected tab selected
    //                        actionBar.setSelectedNavigationItem(position);
    //                    }
    //
    //                    @Override
    //                    public void onPageScrolled(int arg0, float arg1, int arg2) {
    //                    }
    //
    //                    @Override
    //                    public void onPageScrollStateChanged(int arg0) {
    //                    }
    //                });
}

From source file:com.hardcopy.blechat.MainActivity.java

/*****************************************************
 *    Overrided methods/* w w  w  . j  av  a 2  s  .c o m*/
 ******************************************************/

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

    //----- System, Context
    mContext = this; //.getApplicationContext();
    mActivityHandler = new ActivityHandler();
    AppSettings.initializeAppSettings(mContext);

    setContentView(R.layout.activity_main);

    // 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 primary sections of the app.
    mFragmentManager = getSupportFragmentManager();
    mSectionsPagerAdapter = new FragmentAdapter(mFragmentManager, mContext, this, mActivityHandler);

    // 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.
    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.
        actionBar
                .addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }

    // Setup views
    mImageBT = (ImageView) findViewById(R.id.status_title);
    mImageBT.setImageDrawable(getResources().getDrawable(android.R.drawable.presence_invisible));
    mTextStatus = (TextView) findViewById(R.id.status_text);
    mTextStatus.setText(getResources().getString(R.string.bt_state_init));

    // Do data initialization after service started and binded
    doStartService();
}

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 av  a 2  s.  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.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//from   w  ww.  j av a 2 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));
    }

    // 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, "");
        }
    });
}