In my application the selected tab in the actionbar is set to the first one when the orientation is changed, i'd like it to stay on the selected tab, and not jump to the first tab in line...
You can actually do this very easily using onSavedInstanceState:
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
int i = getActionBar().getSelectedNavigationIndex();
outState.putInt("index", i);
}
Then include this in your onCreate() method:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
if(savedInstanceState != null) {
int index = savedInstanceState.getInt("index");
getActionBar().setSelectedNavigationItem(index);
}
}
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