Search code examples
androidandroid-fragmentsactionbarsherlock

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


Solution

  • never mind,

    just used getSherlockActivity().getSupportActionBar()

    Worked perfectly