Skip to content

Instantly share code, notes, and snippets.

@ethankhall
Created April 7, 2013 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ethankhall/5330616 to your computer and use it in GitHub Desktop.
Save ethankhall/5330616 to your computer and use it in GitHub Desktop.
Rotation support for SherlockFragmentActivity and SherlockFragment
public class RootActivity extends SherlockFragmentActivity implements ActionBar.TabListener {
static private Fragment listOfFragments[];
private static final String TAG = RootActivity.class.getName();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState == null) {
setupTempDatabase();
listOfFragments = new Fragment[]{
new Fragment1(),
new Fragment2()
};
}
getSupportActionBar().addTab(
getSupportActionBar()
.newTab()
.setTabListener(this)
.setText("Overview"));
getSupportActionBar().addTab(
getSupportActionBar()
.newTab()
.setTabListener(this)
.setText("Review Entries"));
getSupportActionBar().setTitle("");
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
getSupportActionBar().setDisplayShowTitleEnabled(true);
}
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
if(listOfFragments[tab.getPosition()].isDetached())
ft.attach(listOfFragments[tab.getPosition()]);
else
ft.replace(android.R.id.content, listOfFragments[tab.getPosition()]);
}
public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
ft.remove(listOfFragments[tab.getPosition()]);
}
public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
// User selected the already selected tab. Usually do nothing.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment