0

I create an activity contain tabhost with 3 tabs, also define

android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize">

in the manifest for changed orientation, it helps me to remain on the same tab on landscape mode. But when I create a new xml file for the landscape mode and I put it into res/layout-land.My problem is when I entered into 2nd or 3rd tab and changed to landscape mode it calls the xml in layout- land but tab host switches to 1st tab.Kindly help me on this. thank you.

Anirudh Sharma
  • 7,968
  • 13
  • 40
  • 42
sagar
  • 1

1 Answers1

0

It's better to override @onSaveInstance to save the position of the current tab.

And in onCreate method you can check for the position and set the tab according to the position

@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
    // Save the current position of the tab
    savedInstanceState.putInt(CURRENT_TAB, getTabHost().getCurrentTab());
    super.onSaveInstanceState(savedInstanceState);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Check for the tabPosition Value
    if (savedInstanceState != null) {
    // Restore tab position from saved state and set to TaBHost
    mCurrentTab= savedInstanceState.getInt(CURRENT_TAB);
    }
   //initialize the tabHost and tab
   tabHost.setCurrentTab(mCurrentTab);
Ajay Shrestha
  • 2,433
  • 1
  • 21
  • 25