Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating Action Bar Tabs from a fragment

Is it possible to create ActionBar Tabs from a Fragment?

I am using ABS Library and have 2 Fragments. The data in the second Fragment is changing dynamically and Is it possible to show tabs from a Fragment dynamically?

public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);        
         getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
            for (int i = 1; i <= 3; i++) {
                ActionBar.Tab tab = getSupportActionBar().newTab();
                tab.setText("Tab " + i);
                tab.setTabListener(this);
                getSupportActionBar().addTab(tab);
            }
    }

This is the code I have and I am getting The method getSupportActionBar() is undefined for the type

like image 491
Ajmal Salim Avatar asked Dec 26 '22 14:12

Ajmal Salim


2 Answers

never mind,

just used getSherlockActivity().getSupportActionBar()

Worked perfectly

like image 176
Ajmal Salim Avatar answered Dec 29 '22 02:12

Ajmal Salim


You have to cast to your activity (say ActivityExtendsActionBarActivity) which extends ActionBarActivity:

((ActivityExtendsActionBarActivity)getSupportActionBar()).setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
like image 40
emaleavil Avatar answered Dec 29 '22 02:12

emaleavil