当前位置: 首页>>代码示例>>Java>>正文


Java Fragment.setUserVisibleHint方法代码示例

本文整理汇总了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();
}
 
开发者ID:nekocode,项目名称:Hubs,代码行数:27,代码来源:ExFragmentPagerAdapter.java

示例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;
}
 
开发者ID:yhyzgn,项目名称:FragmentHelper,代码行数:24,代码来源:FmHelper.java

示例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;
}
 
开发者ID:yhyzgn,项目名称:FragmentHelper,代码行数:28,代码来源:FmHelper.java

示例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;
}
 
开发者ID:yhyzgn,项目名称:FragmentHelper,代码行数:23,代码来源:FmHelper.java

示例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();
}
 
开发者ID:JustKiddingBaby,项目名称:FragmentRigger,代码行数:18,代码来源:_Rigger.java

示例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;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:17,代码来源:FragmentsAdapter.java

示例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();
}
 
开发者ID:JustKiddingBaby,项目名称:FragmentRigger,代码行数:19,代码来源:_Rigger.java

示例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;
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:16,代码来源:UpdatableFragmentPagerAdapter.java

示例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;
}
 
开发者ID:yhyzgn,项目名称:FragmentHelper,代码行数:39,代码来源:FmHelper.java

示例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;
}
 
开发者ID:Elias33,项目名称:Quran,代码行数:37,代码来源:FragmentStatePagerAdapter.java

示例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;
  }
}
 
开发者ID:Elias33,项目名称:Quran,代码行数:16,代码来源:FragmentStatePagerAdapter.java

示例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;
    }
}
 
开发者ID:mocircle,项目名称:devsuite-android,代码行数:16,代码来源:MultiFragmentStatePagerAdapter.java

示例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;
}
 
开发者ID:cahergil,项目名称:Farmacias,代码行数:10,代码来源:TabLayoutFragment.java

示例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;
}
 
开发者ID:aliumujib,项目名称:Orin,代码行数:36,代码来源:CustomFragmentStatePagerAdapter.java

示例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;
}
 
开发者ID:yangjiantao,项目名称:AndroidUiKit,代码行数:32,代码来源:TabPagerAdapter.java


注:本文中的android.support.v4.app.Fragment.setUserVisibleHint方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。