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

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

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

FragmentTransaction.attach介绍

暂无

代码示例

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

@Override
public int getItemPosition(@NonNull Object object) {
  if (object instanceof Fragment) {
    mFragmentManager.beginTransaction()
        .detach((Fragment) object)
        .attach((Fragment) object)
        .commit();
  }
  return super.getItemPosition(object);
}

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

if (fragment != null) {
  if (DEBUG) Log.v(TAG, "Attaching item #" + itemId + ": f=" + fragment);
  mCurTransaction.attach(fragment);
} else {
  fragment = getItem(position);

代码示例来源:origin: proninyaroslav/libretorrent

@NonNull
@Override
public Object instantiateItem(ViewGroup container, int position)
{
  if (position < 0 || position >= getCount())
    return null;
  if (curTransaction == null)
    curTransaction = fm.beginTransaction();
  String name = makeFragmentName(container.getId(), position);
  Fragment f = fm.findFragmentByTag(name);
  if (f != null) {
    curTransaction.attach(f);
  } else {
    f = getItem(position);
    curTransaction.add(container.getId(), f,
        makeFragmentName(container.getId(), position));
  }
  if (f != currentPrimaryItem) {
    f.setMenuVisibility(false);
    f.setUserVisibleHint(false);
  }
  registeredFragments.put(position, f);
  return f;
}

代码示例来源:origin: cbeyls/fosdem-companion-android

void selectMenuSection(@NonNull Section section, @NonNull MenuItem menuItem) {
  if (section != currentSection) {
    // Switch to new section
    FragmentManager fm = getSupportFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    Fragment f = fm.findFragmentById(R.id.content);
    if (f != null) {
      if (currentSection.shouldKeep()) {
        ft.detach(f);
      } else {
        ft.remove(f);
      }
    }
    String fragmentClassName = section.getFragmentClassName();
    if (section.shouldKeep() && ((f = fm.findFragmentByTag(fragmentClassName)) != null)) {
      ft.attach(f);
    } else {
      f = Fragment.instantiate(MainActivity.this, fragmentClassName);
      ft.add(R.id.content, f, fragmentClassName);
    }
    ft.commit();
    currentSection = section;
    updateActionBar(section, menuItem);
  }
}

相关文章