當前位置: 首頁>>代碼示例>>Java>>正文


Java Fragment.SavedState方法代碼示例

本文整理匯總了Java中android.support.v4.app.Fragment.SavedState方法的典型用法代碼示例。如果您正苦於以下問題:Java Fragment.SavedState方法的具體用法?Java Fragment.SavedState怎麽用?Java Fragment.SavedState使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.support.v4.app.Fragment的用法示例。


在下文中一共展示了Fragment.SavedState方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: saveState

import android.support.v4.app.Fragment; //導入方法依賴的package包/類
@Override
public Parcelable saveState() {
  Bundle state = new Bundle();
  if (mSavedState.size() > 0) {
    Fragment.SavedState[] fss = new Fragment.SavedState[mSavedState.size()];
    mSavedState.toArray(fss);
    state.putParcelableArray("states", fss);
  }
  for (int i = 0; i < mFragments.size(); i++) {
    Fragment f = mFragments.get(i);
    if (f != null && f.isAdded()) {
      String key = "f" + i;
      mFragmentManager.putFragment(state, key, f);
    }
  }
  state.putString("mode", this.mode);
  return state;
}
 
開發者ID:Elias33,項目名稱:Quran,代碼行數:19,代碼來源:FragmentStatePagerAdapter.java

示例2: instantiateItem

import android.support.v4.app.Fragment; //導入方法依賴的package包/類
@Override
public Object instantiateItem(ViewGroup container, int position)
{
	if(service == null)
		return new View(mainScreen);
	int tabId = service.getTabByPosition(position).id;
	TabFragment fragment = tabFragments.get(tabId);
	if(fragment == null)
	{
		Fragment.SavedState fss = savedStates.get(tabId);
		fragment = new TabFragment();
		fragment.setTabId(tabId);
		fragment.setInitialSavedState(fss);
		if(curTransaction == null)
			curTransaction = fragmentManager.beginTransaction();
		curTransaction.add(container.getId(), fragment);
		tabFragments.put(tabId, fragment);
	}
	return fragment;
}
 
開發者ID:mniip,項目名稱:bananapeel,代碼行數:21,代碼來源:TabAdapter.java

示例3: instantiateItem

import android.support.v4.app.Fragment; //導入方法依賴的package包/類
@Override
public Object instantiateItem(ViewGroup container, int position) {
    final Fragment existing = fragments.get(position);
    if (existing != null) {
        return existing;
    }
    if (currentTransaction == null) {
        currentTransaction = fragmentManager.beginTransaction();
    }
    Fragment fragment = getItem(position);
    if (DEBUG) Log.v(TAG, "Adding item #" + position + ": f=" + fragment);
    if (enableSavedStates && savedState.size() > position) {
        Fragment.SavedState fss = savedState.get(position);
        if (fss != null) {
            fragment.setInitialSavedState(fss);
        }
    }
    if (fragment != currentPrimaryItem) {
        setItemVisible(fragment, false);
    }
    fragments.put(position, fragment);
    currentTransaction.add(container.getId(), fragment);
    return fragment;
}
 
開發者ID:Laaidback,項目名稱:A.scribe,代碼行數:25,代碼來源:FragmentStatePagerAdapter2.java

示例4: instantiateItem

import android.support.v4.app.Fragment; //導入方法依賴的package包/類
@Override
@NonNull
public Object instantiateItem(ViewGroup container, int position) {
    long tag = getItemId(position);
    Fragment fragment = mFragments.get(tag);
    // If we already have this item instantiated, there is nothing
    // to do.  This can happen when we are restoring the entire pager
    // from its saved state, where the fragment manager has already
    // taken care of restoring the fragments we previously had instantiated.
    if (fragment != null) {
        return fragment;
    }

    if (mCurTransaction == null) {
        mCurTransaction = mFragmentManager.beginTransaction();
    }

    fragment = getItem(position);
    // restore state
    final Fragment.SavedState savedState = mSavedStates.get(tag);
    if (savedState != null) {
        fragment.setInitialSavedState(savedState);
    }
    fragment.setMenuVisibility(false);
    fragment.setUserVisibleHint(false);
    mFragments.put(tag, fragment);
    mCurTransaction.add(container.getId(), fragment, "f" + tag);

    return fragment;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:31,代碼來源:UpdatableFragmentPagerAdapter.java

示例5: instantiateItem

import android.support.v4.app.Fragment; //導入方法依賴的package包/類
@SuppressLint("CommitTransaction")
@Override
public Object instantiateItem(ViewGroup container, int position) {
  // If we already have this item instantiated, there is nothing
  // to do.  This can happen when we are restoring the entire pager
  // from its saved state, where the fragment manager has already
  // taken care of restoring the fragments we previously had instantiated.
  if (mFragments.size() > position) {
    Fragment f = mFragments.get(position);
    if (f != null) {
      return f;
    }
  }

  if (mCurTransaction == null) {
    mCurTransaction = mFragmentManager.beginTransaction();
  }

  Fragment fragment = getItem(position);
  if (DEBUG) Timber.v("Adding item #%d: f=%s", position, fragment);
  if (mSavedState.size() > position) {
    Fragment.SavedState fss = mSavedState.get(position);
    if (fss != null) {
      fragment.setInitialSavedState(fss);
    }
  }
  while (mFragments.size() <= position) {
    mFragments.add(null);
  }
  fragment.setMenuVisibility(false);
  fragment.setUserVisibleHint(false);
  mFragments.set(position, fragment);
  mCurTransaction.add(container.getId(), fragment);

  return fragment;
}
 
開發者ID:Elias33,項目名稱:Quran,代碼行數:37,代碼來源:FragmentStatePagerAdapter.java

示例6: getCurrentSavedState

import android.support.v4.app.Fragment; //導入方法依賴的package包/類
private Fragment.SavedState getCurrentSavedState(int position) {
    SparseArray<Fragment.SavedState> states = mSavedState.get(position);
    if (states != null) {
        return states.get(getCurrentViewMode(position));
    } else {
        return null;
    }
}
 
開發者ID:mocircle,項目名稱:devsuite-android,代碼行數:9,代碼來源:MultiFragmentStatePagerAdapter.java

示例7: setSavedState

import android.support.v4.app.Fragment; //導入方法依賴的package包/類
private void setSavedState(int position, int viewMode, Fragment.SavedState savedState) {
    SparseArray<Fragment.SavedState> states = mSavedState.get(position);
    if (states == null) {
        mSavedState.set(position, new SparseArray<Fragment.SavedState>());
    }
    mSavedState.get(position).put(viewMode, savedState);
}
 
開發者ID:mocircle,項目名稱:devsuite-android,代碼行數:8,代碼來源:MultiFragmentStatePagerAdapter.java

示例8: restoreSavedState

import android.support.v4.app.Fragment; //導入方法依賴的package包/類
private void restoreSavedState(Bundle bundle) {
    Iterable<String> keys = bundle.keySet();
    for (String key : keys) {
        if (key.startsWith("states")) {
            int position = Integer.parseInt(key.substring("states".length()));
            while (mSavedState.size() <= position) {
                mSavedState.add(null);
            }
            SparseArray<Fragment.SavedState> states = bundle.getSparseParcelableArray(key);
            mSavedState.set(position, states);
        }
    }
}
 
開發者ID:mocircle,項目名稱:devsuite-android,代碼行數:14,代碼來源:MultiFragmentStatePagerAdapter.java

示例9: instantiateItem

import android.support.v4.app.Fragment; //導入方法依賴的package包/類
@Override
public Object instantiateItem(ViewGroup container, int position) {
    // If we already have this item instantiated, there is nothing
    // to do.  This can happen when we are restoring the entire pager
    // from its saved state, where the fragment manager has already
    // taken care of restoring the fragments we previously had instantiated.
    if (mFragments.size() > position) {
        Fragment f = mFragments.get(position);
        if (f != null) {
            return f;
        }
    }

    if (mCurTransaction == null) {
        mCurTransaction = mFragmentManager.beginTransaction();
    }

    Fragment fragment = getItem(position);
    if (DEBUG) Log.v(TAG, "Adding item #" + position + ": f=" + fragment);
    if (mSavedState.size() > position) {
        Fragment.SavedState fss = mSavedState.get(position);
        if (fss != null) {
            fragment.setInitialSavedState(fss);
        }
    }
    while (mFragments.size() <= position) {
        mFragments.add(null);
    }
    fragment.setMenuVisibility(false);
    fragment.setUserVisibleHint(false);
    mFragments.set(position, fragment);
    mCurTransaction.add(container.getId(), fragment);

    return fragment;
}
 
開發者ID:aliumujib,項目名稱:Orin,代碼行數:36,代碼來源:CustomFragmentStatePagerAdapter.java

示例10: removeToDetachFragment

import android.support.v4.app.Fragment; //導入方法依賴的package包/類
private Fragment removeToDetachFragment(StateChange stateChange, Path key) {
    Fragment fragment = fragmentManager.findFragmentByTag(key.getFragmentTag());
    if(fragment != null && (fragment.isDetached() || fragment.getView() == null)) {
        FragmentTransaction fragmentTransaction = beginFragmentTransaction(stateChange);
        Fragment.SavedState savedState = fragmentManager.saveFragmentInstanceState(fragment);
        fragmentTransaction.remove(fragment);
        fragmentTransaction.commitNow();
        fragment.setInitialSavedState(savedState);
    }
    return fragment;
}
 
開發者ID:Zhuinden,項目名稱:simple-stack,代碼行數:12,代碼來源:MasterDetailFragmentStateChanger.java

示例11: instantiateItem

import android.support.v4.app.Fragment; //導入方法依賴的package包/類
@Override
    public Object instantiateItem(ViewGroup container, int position) {
        // If we already have this item instantiated, there is nothing
        // to do. This can happen when we are restoring the entire pager
        // from its saved state, where the fragment manager has already
        // taken care of restoring the fragments we previously had instantiated.
        Fragment f = mFragments.get(position);
        if (f != null) {
            return f;
        }

        if (mCurTransaction == null) {
            mCurTransaction = mFragmentManager.beginTransaction();
        }

        Fragment fragment = getItem(position);
//		if (DEBUG)
//			Log.v(TAG, "Adding item #" + position + ": f=" + fragment);
        Fragment.SavedState fss = mSavedState.get(position);
        if (fss != null) {
            fragment.setInitialSavedState(fss);
        }
        fragment.setMenuVisibility(false);
        fragment.setUserVisibleHint(false);
        mFragments.put(position, fragment);
        mCurTransaction.add(container.getId(), fragment);

        return fragment;
    }
 
開發者ID:snowwolf10285,項目名稱:PicShow-zhaipin,代碼行數:30,代碼來源:FragmentListPageAdapter.java

示例12: instantiateItem

import android.support.v4.app.Fragment; //導入方法依賴的package包/類
@Override
public Object instantiateItem(ViewGroup container, int position) {
    // If we already have this item instantiated, there is nothing
    // to do.  This can happen when we are restoring the entire pager
    // from its saved state, where the fragment manager has already
    // taken care of restoring the fragments we previously had instantiated.
    if (mFragments.size() > position) {
        Fragment f = getCurrentFragment(position);
        if (f != null) {
            return f;
        }
    }

    if (mCurTransaction == null) {
        mCurTransaction = mFragmentManager.beginTransaction();
    }

    int currentViewMode = getCurrentViewMode(position);
    Fragment fragment = getItem(position, currentViewMode);
    // NEW: record the fragment's position and view mode
    viewModeMap.put(fragment, currentViewMode);
    positionMap.put(fragment, position);
    if (DEBUG)
        Log.v(TAG, "Adding item #" + position + "-" + currentViewMode + ": f=" + fragment);
    if (mSavedState.size() > position) {
        Fragment.SavedState fss = getCurrentSavedState(position);
        if (fss != null) {
            fragment.setInitialSavedState(fss);
        }
    }
    while (mFragments.size() <= position) {
        mFragments.add(null);
    }
    fragment.setMenuVisibility(false);
    fragment.setUserVisibleHint(false);
    setCurrentFragment(position, fragment);

    mCurTransaction.add(container.getId(), fragment);

    return fragment;
}
 
開發者ID:mocircle,項目名稱:devsuite-android,代碼行數:42,代碼來源:MultiFragmentStatePagerAdapter.java

示例13: setCurrentSavedState

import android.support.v4.app.Fragment; //導入方法依賴的package包/類
private void setCurrentSavedState(int position, Fragment.SavedState savedState) {
    setSavedState(position, getCurrentViewMode(position), savedState);
}
 
開發者ID:mocircle,項目名稱:devsuite-android,代碼行數:4,代碼來源:MultiFragmentStatePagerAdapter.java

示例14: getItem

import android.support.v4.app.Fragment; //導入方法依賴的package包/類
/**
 * Return the Fragment associated with a specified position.
 */
public abstract Fragment getItem(int position, Fragment.SavedState savedState);
 
開發者ID:liuyuejinqiu,項目名稱:ScaleViewPager,代碼行數:5,代碼來源:FragmentStatePagerAdapter.java


注:本文中的android.support.v4.app.Fragment.SavedState方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。