当我的活动(具有两个选项卡的选项卡活动)方向发生更改时,选项卡的内容是带有项目列表视图(带复选框)的另一项活动GOES BLANK。我在清单文件中使用了android:configChanges="screenSize|orientation"
,所以我不希望在方向更改时清除(或重新创建)复选框。Android屏幕在方向更改时空白; onConfigurationChanged被调用
任何人都可以请帮我解决这个问题吗?
当我的活动(具有两个选项卡的选项卡活动)方向发生更改时,选项卡的内容是带有项目列表视图(带复选框)的另一项活动GOES BLANK。我在清单文件中使用了android:configChanges="screenSize|orientation"
,所以我不希望在方向更改时清除(或重新创建)复选框。Android屏幕在方向更改时空白; onConfigurationChanged被调用
任何人都可以请帮我解决这个问题吗?
为了在View中保存View的状态,您需要执行onSaveInstanceState(Bundle outState)
和onRestoreInstanceState(Bundle savedInstanceState)
方法。有关这些方法的更多信息,请参阅Android Developer Guide。
onSaveInstanceState(Bundle outState)
当活动在配置更改(方向更改)时被破坏时被调用。您可以使用此方法将数据添加到捆绑包,然后在使用onRestoreInstanceState(Bundle savedInstanceState)
重新启动活动时检索它。
例如:
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
// Read values from the "savedInstanceState" bundle and put them back into the corresponding textviews
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
// Save the values you need from your textviews into the outState object
}
有关如何成束看到Android Developer Guide保存数据的详细信息。这也解释了使用onCreate(Bundle savedInstanceState)
和onRestoreInstanceState(Bundle savedInstanceState)
恢复状态之间的差异。
alri8 thanxxx :) – jstn 2013-04-23 09:32:07
如果这解决了您的问题,请将upvote并接受为答案。谢谢。 – 2013-04-23 09:46:47