2013-04-23 110 views
1

當我的活動(具有兩個選項卡的選項卡活動)方向發生更改時,選項卡的內容是帶有項目列表視圖(帶複選框)的另一項活動GOES BLANK。我在清單文件中使用了android:configChanges="screenSize|orientation",所以我不希望在方向更改時清除(或重新創建)複選框。Android屏幕在方向更改時空白; onConfigurationChanged被調用

任何人都可以請幫我解決這個問題嗎?

回答

3

爲了在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)恢復狀態之間的差異。

+0

alri8 thanxxx :) – jstn 2013-04-23 09:32:07

+0

如果這解決了您的問題,請將upvote並接受爲答案。謝謝。 – 2013-04-23 09:46:47