Android TabHost.setCurrentTab() not working
I have a TabActivity
that I am having problems after the device changes orientation. Followed some places on how to keep the current tab open after the change, but even tho I do get the correct tab number, it always sets it back to 0.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
int currentTab = 1;
if (savedInstanceState != null)
开发者_如何学Python currentTab = savedInstanceState.getInt("tabNumber");
tabHost = getTabHost(); // (TabHost) findViewById(android.R.id.tabhost);
createTabs(tabHost);
tabHost.setCurrentTab(currentTab);
}
protected void onSaveInstanceState(Bundle outState) {
outState.putInt("tabNumber", getTabHost().getCurrentTab());
super.onSaveInstanceState(outState);
}
Am I doing something wrong here?
add this to yout manifest file
..
activity android:name="youractivity"
android:configChanges="orientation|keyboardHidden"
...
Leslie
精彩评论