androidx.fragment.app.Fragment.isAdded()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(5.2k)|赞(0)|评价(0)|浏览(192)

本文整理了Java中androidx.fragment.app.Fragment.isAdded()方法的一些代码示例,展示了Fragment.isAdded()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Fragment.isAdded()方法的具体详情如下:
包路径:androidx.fragment.app.Fragment
类名称:Fragment
方法名:isAdded

Fragment.isAdded介绍

暂无

代码示例

代码示例来源:origin: AppIntro/AppIntro

@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
  if (areColorTransitionsEnabled) {
    if (position < mPagerAdapter.getCount() - 1) {
      if (mPagerAdapter.getItem(position) instanceof ISlideBackgroundColorHolder &&
          mPagerAdapter.getItem(position + 1) instanceof ISlideBackgroundColorHolder) {
        Fragment currentSlide = mPagerAdapter.getItem(position);
        Fragment nextSlide = mPagerAdapter.getItem(position + 1);
        ISlideBackgroundColorHolder currentSlideCasted =
            (ISlideBackgroundColorHolder) currentSlide;
        ISlideBackgroundColorHolder nextSlideCasted =
            (ISlideBackgroundColorHolder) nextSlide;
        // Check if both fragments are attached to an activity,
        // otherwise getDefaultBackgroundColor may fail.
        if (currentSlide.isAdded() && nextSlide.isAdded()) {
          int newColor = (int) argbEvaluator.evaluate(positionOffset,
              currentSlideCasted.getDefaultBackgroundColor(),
              nextSlideCasted.getDefaultBackgroundColor());
          currentSlideCasted.setBackgroundColor(newColor);
          nextSlideCasted.setBackgroundColor(newColor);
        }
      } else {
        throw new IllegalStateException("Color transitions are only available if all slides implement ISlideBackgroundColorHolder.");
      }
    }
  }
}

代码示例来源:origin: niorgai/StatusBarCompat

private void changeTab(int page) {
  if (currentTab == page) {
    return;
  }
  Fragment fragment = fragments.get(page);
  FragmentTransaction ft = MainActivity.this.getSupportFragmentManager().beginTransaction();
  if(!fragment.isAdded()){
    ft.add(fragmentContentId,fragment);
  }
  ft.hide(fragments.get(currentTab));
  ft.show(fragments.get(page));
  changeButtonStatus(currentTab, false);
  currentTab = page;
  changeButtonStatus(currentTab, true);
  if (!this.isFinishing()) {
    ft.commitAllowingStateLoss();
  }
}

代码示例来源:origin: pranavpandey/dynamic-support

@Override
public @NonNull Object instantiateItem(@NonNull ViewGroup container, int position) {
  Fragment fragment = getItem(position);
  if (fragment.isAdded()) {
    return fragment;
  }
  Fragment instantiatedFragment = (Fragment) super.instantiateItem(container, position);
  mDataSet.set(position, (DynamicTutorial) instantiatedFragment);
  return instantiatedFragment;
}

代码示例来源:origin: pranavpandey/dynamic-support

/**
 * Remove a tutorial fragments from the activity.
 *
 * @param dynamicTutorial The tutorial to be removed.
 */
public void removeTutorialFragment(@NonNull DynamicTutorial dynamicTutorial) {
  if (((Fragment) dynamicTutorial).isAdded()) {
    mFragmentManager.beginTransaction().remove((Fragment) dynamicTutorial).commit();
  }
}

代码示例来源:origin: oliexdev/openScale

public void updateScaleData() {
  int selectedUserId = getSelectedScaleUserId();
  scaleMeasurementList = measurementDAO.getAll(selectedUserId);
  for (FragmentUpdateListener fragment : fragmentList) {
    if (fragment != null) {
      if (((Fragment)fragment).isAdded()) {
        fragment.updateOnView(scaleMeasurementList);
      }
    }
  }
}

代码示例来源:origin: VictorAlbertos/RxActivityResult

@Nullable
  Fragment getTargetFragment(List<Fragment> fragments) {
    if (fragments == null) return null;
    for (Fragment fragment : fragments) {
      if (fragment != null && fragment.isVisible() && fragment.getClass() == clazz) {
        return fragment;
      } else if (fragment != null && fragment.isAdded() && fragment.getChildFragmentManager() != null) {
        List<Fragment> childFragments = fragment.getChildFragmentManager().getFragments();
        Fragment candidate = getTargetFragment(childFragments);
        if (candidate != null) return candidate;
      }
    }
    return null;
  }
}

代码示例来源:origin: AlexMofer/ProjectX

@Override
public Parcelable saveState() {
  Bundle state = null;
  if (mSavedState.size() > 0) {
    state = new Bundle();
    Fragment.SavedState[] fss = new Fragment.SavedState[mSavedState.size()];
    mSavedState.toArray(fss);
    state.putParcelableArray("states", fss);
  }
  final int count = getCount();
  for (int position = 0; position < count; position++) {
    final long itemId = getItemId(position);
    String name = makeFragmentName(mViewGroupId, itemId);
    Fragment fragment = mFragmentManager.findFragmentByTag(name);
    if (fragment != null && fragment.isAdded()) {
      if (state == null) {
        state = new Bundle();
      }
      String key = "f" + itemId;
      mFragmentManager.putFragment(state, key, fragment);
    }
  }
  return state;
}

代码示例来源:origin: y20k/transistor

if (mainActivityFragment!= null && mainActivityFragment.isAdded() && newStationList.size() > 0) {
  ((MainActivityFragment)mainActivityFragment).updatePlayerAfterDelete(newStationList.get(stationId));

代码示例来源:origin: AlexMofer/ProjectX

/**
   * Remove all item
   */
  public void removeAll() {
    if (mCurTransaction == null) {
      mCurTransaction = mFragmentManager.beginTransaction();
    }
    final int count = getCount();
    for (int position = 0; position < count; position++) {
      final long itemId = getItemId(position);
      String name = makeFragmentName(mViewGroupId, itemId);
      Fragment fragment = mFragmentManager.findFragmentByTag(name);
      if (fragment == null)
        continue;
      if (DEBUG) Log.v(TAG, "Detaching item #" + itemId + ": f=" + fragment
          + " v=" + fragment.getView());
      while (mSavedState.size() <= getCount()) {
        mSavedState.add(null);
      }
      mSavedState.set(position, fragment.isAdded()
          ? mFragmentManager.saveFragmentInstanceState(fragment) : null);
      mCurTransaction.remove(fragment);
    }
    mCurTransaction.commitNowAllowingStateLoss();
    mCurTransaction = null;
  }
}

相关文章