android.app.FragmentTransaction.add()方法的使用及代码示例

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

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

FragmentTransaction.add介绍

暂无

代码示例

代码示例来源:origin: android10/Android-CleanArchitecture

/**
 * Adds a {@link Fragment} to this activity's layout.
 *
 * @param containerViewId The container view to where add the fragment.
 * @param fragment The fragment to be added.
 */
protected void addFragment(int containerViewId, Fragment fragment) {
 final FragmentTransaction fragmentTransaction = this.getFragmentManager().beginTransaction();
 fragmentTransaction.add(containerViewId, fragment);
 fragmentTransaction.commit();
}

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

public static void startVisibleFragment(Fragment fragment,
  Class<? extends Activity> activityClass, int containerViewId) {
 buildFragmentManager(activityClass)
   .beginTransaction().add(containerViewId, fragment, null).commit();
}

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

public static void startFragment(Fragment fragment) {
 buildFragmentManager(FragmentUtilActivity.class)
   .beginTransaction().add(fragment, null).commit();
}

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

public static void startFragment(Fragment fragment, Class<? extends Activity> activityClass) {
 buildFragmentManager(activityClass)
   .beginTransaction().add(fragment, null).commit();
}

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

public static void startVisibleFragment(Fragment fragment) {
 buildFragmentManager(FragmentUtilActivity.class)
   .beginTransaction().add(1, fragment, null).commit();
}

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

@Override
 public void run() {
  activityController.create(bundle).get().getFragmentManager().beginTransaction().add(contentViewId, fragment).commit();
 }
});

代码示例来源:origin: bumptech/glide

@SuppressWarnings("deprecation")
@NonNull
private RequestManagerFragment getRequestManagerFragment(
  @NonNull final android.app.FragmentManager fm,
  @Nullable android.app.Fragment parentHint,
  boolean isParentVisible) {
 RequestManagerFragment current = (RequestManagerFragment) fm.findFragmentByTag(FRAGMENT_TAG);
 if (current == null) {
  current = pendingRequestManagerFragments.get(fm);
  if (current == null) {
   current = new RequestManagerFragment();
   current.setParentFragmentHint(parentHint);
   if (isParentVisible) {
    current.getGlideLifecycle().onStart();
   }
   pendingRequestManagerFragments.put(fm, current);
   fm.beginTransaction().add(current, FRAGMENT_TAG).commitAllowingStateLoss();
   handler.obtainMessage(ID_REMOVE_FRAGMENT_MANAGER, fm).sendToTarget();
  }
 }
 return current;
}

代码示例来源:origin: commonsguy/cw-omnibus

@Override
protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 if (getFragmentManager().findFragmentById(android.R.id.content)==null) {
  getFragmentManager()
   .beginTransaction()
   .add(android.R.id.content, new Display())
   .commit();
 }
}

代码示例来源:origin: commonsguy/cw-omnibus

@Override
protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 if (getFragmentManager().findFragmentById(android.R.id.content) == null) {
  getFragmentManager().beginTransaction()
            .add(android.R.id.content,
               new QuestionsFragment()).commit();
 }
}

代码示例来源:origin: commonsguy/cw-omnibus

@Override
public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 if (getFragmentManager().findFragmentById(android.R.id.content)==null) {
  getFragmentManager().beginTransaction()
    .add(android.R.id.content,
      new Prefs()).commit();
 }
}

代码示例来源:origin: commonsguy/cw-omnibus

@Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  if (getFragmentManager().findFragmentById(android.R.id.content)==null) {
   getFragmentManager().beginTransaction()
    .add(android.R.id.content,
     new SettingsFragment()).commit();
  }
 }
}

代码示例来源:origin: commonsguy/cw-omnibus

@Override
protected void onReady() {
 if (getFragmentManager().findFragmentById(android.R.id.content)==null) {
  getFragmentManager().beginTransaction()
   .add(android.R.id.content,
    new Prefs()).commit();
 }
}

代码示例来源:origin: commonsguy/cw-omnibus

@Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  if (getFragmentManager().findFragmentById(android.R.id.content) == null) {
   getFragmentManager().beginTransaction()
             .add(android.R.id.content,
                new EventLogFragment()).commit();

   PollReceiver.scheduleAlarms(this);
  }
 }
}

代码示例来源:origin: commonsguy/cw-omnibus

@Override
public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.main);
 details=
   (DetailsFragment)getFragmentManager().findFragmentById(R.id.details);
 if (details == null && findViewById(R.id.details) != null) {
  details=new DetailsFragment();
  getFragmentManager().beginTransaction()
                .add(R.id.details, details).commit();
 }
}

代码示例来源:origin: bumptech/glide

@SuppressWarnings("deprecation")
@Test
@RequiresApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public void testDoesNotThrowIfAskedToGetManagerForFragmentPreJellyBeanMr1() {
 Util.setSdkVersionInt(Build.VERSION_CODES.JELLY_BEAN);
 Activity activity = Robolectric.buildActivity(Activity.class).create().start().resume().get();
 android.app.Fragment fragment = new android.app.Fragment();
 activity.getFragmentManager().beginTransaction().add(fragment, "test").commit();
 android.app.Fragment spyFragment = Mockito.spy(fragment);
 when(spyFragment.getChildFragmentManager()).thenThrow(new NoSuchMethodError());
 assertNotNull(retriever.get(spyFragment));
}

代码示例来源:origin: bumptech/glide

public RequestManagerHarness() {
 fragment = new RequestManagerFragment(lifecycle);
 controller = Robolectric.buildActivity(Activity.class).create();
 controller.get()
   .getFragmentManager()
   .beginTransaction()
   .add(fragment, TAG)
   .commit();
 controller.get()
   .getFragmentManager()
   .executePendingTransactions();
}

代码示例来源:origin: bumptech/glide

@SuppressWarnings("deprecation")
 @Override
 public void addFragmentWithTag(String tag, RequestManager requestManager) {
  RequestManagerFragment fragment = new RequestManagerFragment();
  fragment.setRequestManager(requestManager);
  controller.get().getFragmentManager().beginTransaction()
    .add(fragment, RequestManagerRetriever.FRAGMENT_TAG).commitAllowingStateLoss();
  controller.get().getFragmentManager().executePendingTransactions();
 }
}

代码示例来源:origin: bumptech/glide

@SuppressWarnings("deprecation")
@Test
public void testCanGetRequestManagerFromFragment() {
 Activity activity = Robolectric.buildActivity(Activity.class).create().start().resume().get();
 android.app.Fragment fragment = new android.app.Fragment();
 activity.getFragmentManager().beginTransaction().add(fragment, PARENT_TAG).commit();
 activity.getFragmentManager().executePendingTransactions();
 RequestManager manager = retriever.get(fragment);
 assertEquals(manager, retriever.get(fragment));
}

代码示例来源:origin: bumptech/glide

@SuppressWarnings("deprecation")
private void helpTestCanGetRequestManagerFromDetachedFragment() {
 Activity activity = Robolectric.buildActivity(Activity.class).create().start().resume().get();
 android.app.Fragment fragment = new android.app.Fragment();
 activity.getFragmentManager().beginTransaction().add(fragment, PARENT_TAG).detach(fragment)
   .commit();
 activity.getFragmentManager().executePendingTransactions();
 assertTrue(fragment.isDetached());
 retriever.get(fragment);
}

代码示例来源:origin: bumptech/glide

DefaultRetrieverHarness() {
 this.parent = new android.app.Fragment();
 controller.create();
 controller.get().getFragmentManager().beginTransaction().add(parent, PARENT_TAG)
   .commitAllowingStateLoss();
 controller.get().getFragmentManager().executePendingTransactions();
 controller.start().resume();
}

相关文章