0
我在Tab Fragment(它有3個標籤)中使用Listview,當點擊列表視圖時,啓動一個webviewer,它可以通過後退按鈕返回。如何恢復從活動回來後的標籤位置
列表單擊後,它會調用一個新的活動(意圖),然後Tab將覆蓋並顯示一個後退按鈕。
問題:如何保存Tab位置並在從webview活動返回後恢復它。
** API:21在Android Studio中
感謝
我在Tab Fragment(它有3個標籤)中使用Listview,當點擊列表視圖時,啓動一個webviewer,它可以通過後退按鈕返回。如何恢復從活動回來後的標籤位置
列表單擊後,它會調用一個新的活動(意圖),然後Tab將覆蓋並顯示一個後退按鈕。
問題:如何保存Tab位置並在從webview活動返回後恢復它。
** API:21在Android Studio中
感謝
定義爲int,以保持當前選項卡的軌道類:
public static SharedPreferences mSetupSharedPreferences;
public static final String CURRENT_TAB = "currentTab";
private static final in mCurrentTab;
使用共享偏好保存此mCurrentTab永久,將此代碼置於OnCreate()中:
mSetupSharedPreferences = getSharedPreferences(SETUP_PREFERENCES,
Context.MODE_PRIVATE);
// If it does not contain the CURRENT_TAB then create one
if (! mSetupSharedPreferences.contains(CURRENT_TAB)) {
SharedPreferences.Editor setup_editor = mSetupSharedPreferences.edit();
setup_editor.putInt(CURRENT_TAB, 1); // 1 means the current tab number is 1
setup_editor.apply();
}
現在保存cu
SharedPreferences.Editor editor = mSetupSharedPreferences.edit();
editor.putInt(CURRENT_TAB, current_tab);
而當用戶按下返回按鈕然後讀取當前選項卡並設置視圖:
int currentTab = mSetupSharedPreferences.getInt(CURRENT_TAB, 0)
switch (currentTab) {
case 1: // Switch tab view here to 1
break;
case 2: // Switch tab view here to 2
break;
case 3: // Switch tab view here to 3
break;
}
每當用戶切換的標籤rrent標籤