Created
April 7, 2013 14:03
-
-
Save ethankhall/5330616 to your computer and use it in GitHub Desktop.
Rotation support for SherlockFragmentActivity and SherlockFragment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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