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

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

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

Fragment.instantiate介绍

暂无

代码示例

代码示例来源:origin: bkhezry/ExtraWebView

@Override
public Fragment getItem(int position) {
  if (mFragments[position] != null) {
    return mFragments[position];
  }
  String fragmentName;
  Bundle args = new Bundle();
  args.putBoolean(LazyLoadFragment.EXTRA_EAGER_LOAD, mDefaultItem == position);
  args.putSerializable(WebFragment.EXTRA_ITEM, mItem);
  fragmentName = WebFragment.class.getName();
  return Fragment.instantiate(mContext, fragmentName, args);
}

代码示例来源:origin: morogoku/MTweaks-KernelAdiutorMOD

private Fragment getFragment(int res) {
  FragmentManager fragmentManager = getSupportFragmentManager();
  Fragment fragment = fragmentManager.findFragmentByTag(res + "_key");
  if (fragment == null && mActualFragments.containsKey(res)) {
    fragment = Fragment.instantiate(this,
        mActualFragments.get(res).getCanonicalName());
  }
  return fragment;
}

代码示例来源:origin: michael-rapp/AndroidMaterialDialog

@Override
public final Fragment getItem(final int index) {
  ViewPagerItem item = items.get(index);
  Class<? extends Fragment> fragmentClass = item.getFragmentClass();
  Bundle arguments = item.getArguments();
  return Fragment.instantiate(context, fragmentClass.getName(), arguments);
}

代码示例来源:origin: luhaoaimama1/zone-sdk

public void initFragment(Class... fragments){
  for (int i = 0; i < fragments.length; i++) {
    Class fragment = fragments[i];
    if(!Fragment.class.isAssignableFrom(fragment))
      throw new IllegalArgumentException("类型不是frament 不能展示");
    else{
      FragmentEntity entity = new FragmentEntity();
      entity.fragment=Fragment.instantiate(frameActivity,fragment.getName());
      if((ani_in_pri!=-1||ani_out_pri!=-1)){
        entity.ani_in=ani_in_pri;
        entity.ani_out=ani_out_pri;
      }
      entity.tag=TAG+i;
      fragmentEntityList.add(entity);
    }
  }
  init=true;
}
private boolean init=false;

代码示例来源:origin: morogoku/MTweaks-KernelAdiutorMOD

public Fragment getFragment(int res, Class<? extends Fragment> fragmentClass) {
  FragmentManager fragmentManager = getSupportFragmentManager();
  Fragment fragment = fragmentManager.findFragmentByTag(res + "_key");
  if (fragment == null) {
    fragment = Fragment.instantiate(this, fragmentClass.getCanonicalName());
  }
  return fragment;
}

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

protected void showFragment(Class<? extends Fragment> fragmentClass) {
  Fragment fragment = Fragment.instantiate(this, fragmentClass.getName());
  FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
  transaction.replace(R.id.fragmentOne, fragment, "fragment").commit();
}

代码示例来源:origin: michael-rapp/AndroidMaterialPreferences

@Override
protected final void onCreate(final Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  Fragment fragment = getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG);
  if (fragment == null) {
    fragment = Fragment.instantiate(this, PreferenceFragment.class.getName());
  }
  FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
  transaction.replace(R.id.fragment, fragment);
  transaction.commit();
}

代码示例来源:origin: michael-rapp/AndroidMaterialDialog

@Override
protected final void onCreate(final Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  if (getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG) == null) {
    fragment = (PreferenceFragment) Fragment
        .instantiate(this, PreferenceFragment.class.getName());
    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    transaction.replace(R.id.fragment, fragment, FRAGMENT_TAG);
    transaction.commit();
  }
  initializeFloatingActionButton();
}

代码示例来源:origin: raphaelbussa/PermissionUtils

@SuppressWarnings("ConstantConditions")
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_fragment);
  boolean isFragmentX = getIntent().getExtras().getBoolean("IS_FRAGMENT_X");
  if (getSupportActionBar() != null) {
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setSubtitle(isFragmentX ? "Fragment V4" : "Fragment");
  }
  if (isFragmentX) {
    if (savedInstanceState == null) {
      androidx.fragment.app.Fragment fragment = androidx.fragment.app.Fragment.instantiate(this, SecondFragmentX.class.getName());
      getSupportFragmentManager().beginTransaction()
          .add(R.id.container, fragment, SECOND_FRAGMENT_X)
          .commit();
    }
  } else {
    if (savedInstanceState == null) {
      android.app.Fragment fragment = android.app.Fragment.instantiate(this, SecondFragment.class.getName());
      getFragmentManager().beginTransaction()
          .add(R.id.container, fragment, SECOND_FRAGMENT)
          .commit();
    }
  }
}

代码示例来源:origin: michael-rapp/AndroidPreferenceActivity

Fragment fragment = Fragment.instantiate(this, navigationPreference.getFragment(),
    selectedPreferenceFragmentArguments);
showPreferenceFragment(navigationPreference, fragment);

代码示例来源: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);
  }
}

代码示例来源:origin: michael-rapp/AndroidPreferenceActivity

/**
 * Initializes the activity's fragments.
 */
private void initializeFragments() {
  navigationFragment = (NavigationFragment) getSupportFragmentManager()
      .findFragmentByTag(NAVIGATION_FRAGMENT_TAG);
  if (navigationFragment == null) {
    navigationFragment = (NavigationFragment) Fragment
        .instantiate(this, NavigationFragment.class.getName());
    navigationFragment.setRetainInstance(true);
    navigationFragment.setCallback(this);
    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    transaction.add(R.id.navigation_fragment_container, navigationFragment,
        NAVIGATION_FRAGMENT_TAG);
    transaction.commit();
  } else if (!navigationFragment.isAdapterCreated()) {
    navigationFragment.setCallback(this);
  }
  navigationFragment.setAdapterCallback(this);
  preferenceFragment = getSupportFragmentManager().findFragmentByTag(PREFERENCE_FRAGMENT_TAG);
  adaptNavigationSelectionColor();
  adaptNavigationDividerColor();
  adaptNavigationEnabledState();
}

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

Fragment f = Fragment.instantiate(this, fragmentClassName);
getSupportFragmentManager().beginTransaction().add(R.id.content, f, fragmentClassName).commit();

相关文章