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
never mind,
just used getSherlockActivity().getSupportActionBar()
Worked perfectly
You have to cast to your activity (say ActivityExtendsActionBarActivity
) which extends ActionBarActivity
:
((ActivityExtendsActionBarActivity)getSupportActionBar()).setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With