本文整理匯總了Java中android.support.v4.app.Fragment.setUserVisibleHint方法的典型用法代碼示例。如果您正苦於以下問題:Java Fragment.setUserVisibleHint方法的具體用法?Java Fragment.setUserVisibleHint怎麽用?Java Fragment.setUserVisibleHint使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.support.v4.app.Fragment
的用法示例。
在下文中一共展示了Fragment.setUserVisibleHint方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: hackRecreateFragment
import android.support.v4.app.Fragment; //導入方法依賴的package包/類
/**
* Trick:
* Manually recreate fragment when corresponding data changed
*/
public void hackRecreateFragment(int position) {
final FragmentTransaction transaction = mFragmentManager.beginTransaction();
final String tag = makeFragmentTag(mContainerId, getItemId(position));
final Fragment oldFrg = mFragmentManager.findFragmentByTag(tag);
if (oldFrg != null) {
final Fragment newFrg = getItem(position);
transaction.remove(oldFrg);
transaction.add(mContainerId, newFrg, tag);
if (oldFrg != mCurrentPrimaryItem) {
newFrg.setMenuVisibility(false);
newFrg.setUserVisibleHint(false);
} else {
newFrg.setMenuVisibility(true);
newFrg.setUserVisibleHint(true);
}
}
transaction.commitNowAllowingStateLoss();
}
示例2: add
import android.support.v4.app.Fragment; //導入方法依賴的package包/類
private FmHelper add(Fragment fm) {
// 開啟事務添加頁麵
mFm.beginTransaction()
.setCustomAnimations(mAnimEnter, mAnimExit)
.add(mContainerId, fm)
.commit();
// 由於上述commit()是延時操作,在這裏強製及時執行事務,就能避免很多Fragment中的NullPointerException異常,比如getActivity()為null
mFm.executePendingTransactions();
// 主動觸發頁麵的顯示和隱藏回調
if (null != mCurrentFm) {
mCurrentFm.setUserVisibleHint(false);
}
fm.setUserVisibleHint(true);
// 更新當前Fragment
mCurrentFm = fm;
// Fragment入棧
mFmList.add(fm);
return this;
}
示例3: replace
import android.support.v4.app.Fragment; //導入方法依賴的package包/類
/**
* 替換Fragment
*
* @param fm 需要顯示的Fragment
* @return
*/
private FmHelper replace(Fragment fm) {
mFm.beginTransaction()
.setCustomAnimations(mAnimEnter, mAnimExit)
.replace(mContainerId, fm)
.commit();
mFm.executePendingTransactions();
if (null != mCurrentFm) {
mCurrentFm.setUserVisibleHint(false);
// 將當前Fragment從棧中移除
mFmList.remove(mCurrentFm);
}
fm.setUserVisibleHint(true);
mCurrentFm = fm;
mFmList.add(fm);
return this;
}
示例4: show
import android.support.v4.app.Fragment; //導入方法依賴的package包/類
/**
* 顯示某個Fragment
*
* @param fm 要顯示的Fragment
* @return 當前對象
*/
private FmHelper show(Fragment fm) {
mFm.beginTransaction()
.setCustomAnimations(mAnimEnter, mAnimExit)
.show(fm)
.commit();
mFm.executePendingTransactions();
if (null != mCurrentFm) {
mCurrentFm.setUserVisibleHint(false);
}
fm.setUserVisibleHint(true);
mCurrentFm = fm;
return this;
}
示例5: showFragment
import android.support.v4.app.Fragment; //導入方法依賴的package包/類
@Override
public void showFragment(@NonNull Fragment fragment, @IdRes int containerViewId) {
String fragmentTAG = Rigger.getRigger(fragment).getFragmentTAG();
if (mStackManager.add(fragmentTAG, containerViewId)) {
addFragmentWithAnim(fragment, containerViewId);
}
String[] fragmentTags = mStackManager.getFragmentTags(containerViewId);
for (String tag : fragmentTags) {
Fragment hideFrag = mRiggerTransaction.find(tag);
if (hideFrag == null) continue;
hideFrag.setUserVisibleHint(false);
}
fragment.setUserVisibleHint(true);
showFragmentWithAnim(fragment);
mRiggerTransaction.hide(getVisibleFragmentTags(containerViewId));
mRiggerTransaction.commit();
}
示例6: instantiateItem
import android.support.v4.app.Fragment; //導入方法依賴的package包/類
@Override
public Object instantiateItem(ViewGroup container, int position) {
if (mCurTransaction == null) {
mCurTransaction = mFragmentManager.beginTransaction();
}
Fragment fragment = getItem(position);
if (DEBUG) Log.v(TAG, "Adding item #" + position + ": f=" + fragment);
fragment.setMenuVisibility(false);
fragment.setUserVisibleHint(false);
mCurTransaction.add(container.getId(), fragment);
return fragment;
}
示例7: addFragment
import android.support.v4.app.Fragment; //導入方法依賴的package包/類
@Override
public void addFragment(@IdRes int containerViewId, Fragment... fragments) {
if (fragments == null) {
Logger.w(this, "the fragments to be added is null.");
return;
}
for (Fragment fragment : fragments) {
String fragmentTAG = Rigger.getRigger(fragment).getFragmentTAG();
if (mStackManager.add(fragmentTAG, containerViewId)) {
addFragmentWithAnim(fragment, containerViewId);
mRiggerTransaction.hide(fragmentTAG);
} else {
throwException(new AlreadyExistException(fragmentTAG));
}
fragment.setUserVisibleHint(false);
}
mRiggerTransaction.commit();
}
示例8: setPrimaryItem
import android.support.v4.app.Fragment; //導入方法依賴的package包/類
@Override
public void setPrimaryItem(ViewGroup container, int position, @Nullable Object object) {
Fragment fragment = (Fragment) object;
if (fragment != mCurrentPrimaryItem) {
if (mCurrentPrimaryItem != null) {
mCurrentPrimaryItem.setMenuVisibility(false);
mCurrentPrimaryItem.setUserVisibleHint(false);
}
if (fragment != null) {
fragment.setMenuVisibility(true);
fragment.setUserVisibleHint(true);
}
mCurrentPrimaryItem = fragment;
}
}
示例9: remove
import android.support.v4.app.Fragment; //導入方法依賴的package包/類
/**
* 移除某個Fragment
* <p>
* 在將要顯示的Fragment的setUserVisibleHint()方法中能獲取到被移除頁麵返回的參數
*
* @param fm 要移除的Fragment
* @return 當前對象
*/
private FmHelper remove(Fragment fm) {
mFm.beginTransaction()
.setCustomAnimations(mAnimEnter, mAnimExit)
.remove(fm)
.commit();
mFm.executePendingTransactions();
mFmList.remove(fm);
mCurrentFm = getLastFm();
fm.setUserVisibleHint(false);
if (null != mCurrentFm) {
// 采用回調方式,模擬onActivityResult()方法了
// 當前頁麵的回調對象,也就是將要重新顯示的頁麵
OnFmCallBack currentFmCb = FmCbManager.getInstance().getCallBack(mCurrentFm);
// 上一個頁麵的回調對象
OnFmCallBack lastFmCb = FmCbManager.getInstance().getCallBack(fm);
if (null != currentFmCb && null != lastFmCb) {
currentFmCb.onResult(lastFmCb.getResult());
}
// 回調setUserVisibleHint()方法
mCurrentFm.setUserVisibleHint(true);
}
return this;
}
示例10: 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;
}
示例11: setPrimaryItem
import android.support.v4.app.Fragment; //導入方法依賴的package包/類
@Override
public void setPrimaryItem(ViewGroup container, int position, Object object) {
Fragment fragment = (Fragment) object;
if (fragment != mCurrentPrimaryItem) {
if (mCurrentPrimaryItem != null) {
mCurrentPrimaryItem.setMenuVisibility(false);
mCurrentPrimaryItem.setUserVisibleHint(false);
}
if (fragment != null) {
fragment.setMenuVisibility(true);
fragment.setUserVisibleHint(true);
}
mCurrentPrimaryItem = fragment;
}
}
示例12: setPrimaryItem
import android.support.v4.app.Fragment; //導入方法依賴的package包/類
@Override
public void setPrimaryItem(ViewGroup container, int position, Object object) {
Fragment fragment = (Fragment) object;
if (fragment != mCurrentPrimaryItem) {
if (mCurrentPrimaryItem != null) {
mCurrentPrimaryItem.setMenuVisibility(false);
mCurrentPrimaryItem.setUserVisibleHint(false);
}
if (fragment != null) {
fragment.setMenuVisibility(true);
fragment.setUserVisibleHint(true);
}
mCurrentPrimaryItem = fragment;
}
}
示例13: instantiateItem
import android.support.v4.app.Fragment; //導入方法依賴的package包/類
@Override
public Object instantiateItem(ViewGroup container, int position) {
//Utils.logD(LOG_TAG,"instantiateItem:"+position);
Fragment fragment = (Fragment) super.instantiateItem(container, position);
fragment.setUserVisibleHint(true);
registeredFragments.put(position, fragment);
return fragment;
}
示例14: 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;
}
示例15: instantiateItem
import android.support.v4.app.Fragment; //導入方法依賴的package包/類
@Override
public Object instantiateItem(ViewGroup container, int position) {
if (mCurTransaction == null) {
mCurTransaction = mFragmentManager.beginTransaction();
}
final long itemId = getItemId(position);
// Do we already have this fragment?
String name = makeFragmentName(container.getId(), itemId);
Fragment fragment = mFragmentManager.findFragmentByTag(name);
if (fragment != null) {
if (DEBUG) Log.v(TAG, "Attaching item #" + itemId + ": f=" + fragment);
if(retainPagesState){
mCurTransaction.show(fragment);
}else{
mCurTransaction.attach(fragment);
}
} else {
fragment = getItem(position);
if (DEBUG) Log.v(TAG, "Adding item #" + itemId + ": f=" + fragment);
mCurTransaction.add(container.getId(), fragment,
makeFragmentName(container.getId(), itemId));
}
if (fragment != mCurrentPrimaryItem) {
fragment.setMenuVisibility(false);
fragment.setUserVisibleHint(false);
}
return fragment;
}