android.app.FragmentManager.findFragmentByTag()方法的使用及代码示例

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

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

FragmentManager.findFragmentByTag介绍

暂无

代码示例

代码示例来源:origin: bluelinelabs/Conductor

@Nullable
private static LifecycleHandler findInActivity(@NonNull Activity activity) {
  LifecycleHandler lifecycleHandler = activeLifecycleHandlers.get(activity);
  if (lifecycleHandler == null) {
    lifecycleHandler = (LifecycleHandler)activity.getFragmentManager().findFragmentByTag(FRAGMENT_TAG);
  }
  if (lifecycleHandler != null) {
    lifecycleHandler.registerActivityListener(activity);
  }
  return lifecycleHandler;
}

代码示例来源: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: square/assertj-android

public FragmentManagerAssert hasFragmentWithTag(String tag) {
 isNotNull();
 assertThat(actual.findFragmentByTag(tag)) //
   .overridingErrorMessage("Expected fragment with tag <%s> but was not found.", tag) //
   .isNotNull();
 return this;
}

代码示例来源:origin: square/assertj-android

public FragmentManagerAssert doesNotHaveFragmentWithTag(String tag) {
  isNotNull();
  assertThat(actual.findFragmentByTag(tag))
    .overridingErrorMessage("Expected fragment with tag <%s> not to be present but was.", tag)
    .isNull();
  return this;
 }
}

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

@Override
public boolean hasFragmentWithTag(String tag) {
 return null != controller
   .get()
   .getFragmentManager()
   .findFragmentByTag(RequestManagerRetriever.FRAGMENT_TAG);
}

代码示例来源:origin: wangdan/AisenWeiBo

@Override
public Fragment getItem(int position) {
  Fragment fragment = getFragmentManager().findFragmentByTag(makeFragmentName(position));
  if (fragment == null) {
    fragment = newFragment(position);
  }
  
  return fragment;
}

代码示例来源:origin: wangdan/AisenWeiBo

@Override
public Fragment getItem(int position) {
  Fragment fragment = getFragmentManager().findFragmentByTag(makeFragmentName(position));
  if (fragment == null) {
    fragment = newFragment(position);
  }
  
  return fragment;
}

代码示例来源:origin: wangdan/AisenWeiBo

public static void launch(Activity context) {
  Fragment fragment = context.getFragmentManager().findFragmentByTag("DMColorsDialogFragment");
  if (fragment != null) {
    context.getFragmentManager().beginTransaction().remove(fragment).commit();
  }
  
  MDColorsDialogFragment dialogFragment = new MDColorsDialogFragment();
  dialogFragment.show(context.getFragmentManager(), "DMColorsDialogFragment");
}

代码示例来源:origin: wangdan/AisenWeiBo

public static void launch(Activity context) {
  Fragment fragment = context.getFragmentManager().findFragmentByTag("DialogFragment");
  if (fragment != null) {
    context.getFragmentManager().beginTransaction().remove(fragment).commit();
  }
  
  CustomThemeColorFragment dialogFragment = new CustomThemeColorFragment();
  dialogFragment.show(context.getFragmentManager(), "DialogFragment");
}

代码示例来源:origin: wangdan/AisenWeiBo

public static void launch(Activity context) {
  Fragment fragment = context.getFragmentManager().findFragmentByTag("DialogFragment");
  if (fragment != null) {
    context.getFragmentManager().beginTransaction().remove(fragment).commit();
  }
  
  VersionDialogFragment dialogFragment = new VersionDialogFragment();
  dialogFragment.show(context.getFragmentManager(), "DialogFragment");
}

代码示例来源:origin: wangdan/AisenWeiBo

@Override
public void destroyItem(ViewGroup container, int position, Object object) {
  super.destroyItem(container, position, object);
  
  Fragment fragment = getFragmentManager().findFragmentByTag(makeFragmentName(position));
  if (fragment != null)
    mCurTransaction.remove(fragment);
}

代码示例来源:origin: wangdan/AisenWeiBo

@Override
public void destroyItem(ViewGroup container, int position, Object object) {
  super.destroyItem(container, position, object);
  
  Fragment fragment = getFragmentManager().findFragmentByTag(makeFragmentName(position));
  if (fragment != null)
    mCurTransaction.remove(fragment);
}

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

@Before
public void before() {
 this.fragment = (TestPreferenceFragment) this.activity.getFragmentManager().findFragmentByTag(FRAGMENT_TAG);
}

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

@Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  if (savedInstanceState == null) {
   retainedFragment = new Fragment();
   retainedFragment.setRetainInstance(true);
   nonRetainedFragment = new Fragment();
   getFragmentManager().beginTransaction()
     .add(android.R.id.content, retainedFragment, "retained")
     .add(android.R.id.content, nonRetainedFragment, "non-retained")
     .commit();
  } else {
   retainedFragment = getFragmentManager().findFragmentByTag("retained");
   nonRetainedFragment = getFragmentManager().findFragmentByTag("non-retained");
  }
 }
}

代码示例来源:origin: wangdan/AisenWeiBo

@Override
protected void onFinished() {
  super.onFinished();
  if (getActivity() != null) {
    Fragment fragment = getActivity().getFragmentManager().findFragmentByTag(SinaCommonActivity.FRAGMENT_TAG);
    if (fragment != null && fragment instanceof TimelineDetailPagerFragment) {
      ((TimelineDetailPagerFragment) fragment).refreshEnd();
    }
  }
}

代码示例来源:origin: wangdan/AisenWeiBo

@Override
public void onFriendshipDestoryed(WeiBoUser targetUser) {
  if (mFriendship != null)
    mFriendship.getSource().setFollowing(false);
  mGroupMemberListed = null;
  mUser.setRemark("");
  setProfile();
  // 设置Pager的菜单显示
  Fragment fragment = getActivity().getFragmentManager().findFragmentByTag(SinaCommonActivity.FRAGMENT_TAG);
  ((ProfilePagerFragment) fragment).setFriendshipShow(mFriendship);
}

代码示例来源:origin: wangdan/AisenWeiBo

@Override
protected void onSuccess(FriendshipShow result) {
  super.onSuccess(result);
  if (getActivity() != null) {
    mFriendship = result;
    // 设置Pager的菜单显示
    Fragment fragment = getActivity().getFragmentManager().findFragmentByTag(SinaCommonActivity.FRAGMENT_TAG);
    ((ProfilePagerFragment) fragment).setFriendshipShow(mFriendship);
    getActivity().invalidateOptionsMenu();
    setProfile();
  }
}

代码示例来源:origin: googlesamples/easypermissions

@Test
public void shouldShowCorrectDialog_whenMissingPermissionsAndShowRationaleFromActivity() {
  grantPermissions(ONE_PERM);
  showRationale(true, ALL_PERMS);
  EasyPermissions.requestPermissions(spyActivity, RATIONALE, TestActivity.REQUEST_CODE, ALL_PERMS);
  Fragment dialogFragment = spyActivity.getFragmentManager()
      .findFragmentByTag(RationaleDialogFragment.TAG);
  assertThat(dialogFragment).isInstanceOf(RationaleDialogFragment.class);
  Dialog dialog = ((RationaleDialogFragment) dialogFragment).getDialog();
  assertThatHasExpectedRationale(dialog, RATIONALE);
}

代码示例来源:origin: googlesamples/easypermissions

@Test
public void shouldShowCorrectDialog_whenMissingPermissionsAndShowRationaleFromSupportFragmentActivity() {
  grantPermissions(ONE_PERM);
  showRationale(true, ALL_PERMS);
  EasyPermissions.requestPermissions(spySupportFragmentActivity, RATIONALE, TestSupportFragmentActivity.REQUEST_CODE, ALL_PERMS);
  Fragment dialogFragment = spySupportFragmentActivity.getFragmentManager()
      .findFragmentByTag(RationaleDialogFragment.TAG);
  assertThat(dialogFragment).isInstanceOf(RationaleDialogFragment.class);
  Dialog dialog = ((RationaleDialogFragment) dialogFragment).getDialog();
  assertThatHasExpectedRationale(dialog, RATIONALE);
}

代码示例来源:origin: googlesamples/easypermissions

@Test
public void shouldShowCorrectDialogUsingRequest_whenMissingPermissionsAndShowRationaleFromActivity() {
  grantPermissions(ONE_PERM);
  showRationale(true, ALL_PERMS);
  PermissionRequest request = new PermissionRequest.Builder(spyActivity, TestActivity.REQUEST_CODE, ALL_PERMS)
      .setPositiveButtonText(android.R.string.ok)
      .setNegativeButtonText(android.R.string.cancel)
      .setRationale(android.R.string.unknownName)
      .setTheme(R.style.Theme_AppCompat)
      .build();
  EasyPermissions.requestPermissions(request);
  Fragment dialogFragment = spyActivity.getFragmentManager()
      .findFragmentByTag(RationaleDialogFragment.TAG);
  assertThat(dialogFragment).isInstanceOf(RationaleDialogFragment.class);
  Dialog dialog = ((RationaleDialogFragment) dialogFragment).getDialog();
  assertThatHasExpectedButtonsAndRationale(dialog, android.R.string.unknownName,
      android.R.string.ok, android.R.string.cancel);
}

相关文章