当前位置: 首页>>代码示例>>Java>>正文


Java Fragment.getParentFragment方法代码示例

本文整理汇总了Java中android.support.v4.app.Fragment.getParentFragment方法的典型用法代码示例。如果您正苦于以下问题:Java Fragment.getParentFragment方法的具体用法?Java Fragment.getParentFragment怎么用?Java Fragment.getParentFragment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.support.v4.app.Fragment的用法示例。


在下文中一共展示了Fragment.getParentFragment方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getFragmentManager

import android.support.v4.app.Fragment; //导入方法依赖的package包/类
/**
 * get fragment manager
 *
 * @param fragmentActivity
 * @return
 */
private FragmentManager getFragmentManager(FragmentActivity fragmentActivity) {
    Fragment fragment = null;
    if (fragmentActivity != null && fragmentActivity.getSupportFragmentManager() != null && fragmentActivity.getSupportFragmentManager().getFragments() != null && fragmentActivity.getSupportFragmentManager().getFragments().size() > 0) {
        fragment = fragmentActivity.getSupportFragmentManager().getFragments().get(0);
    }
    if (fragment != null && fragment.getParentFragment() != null) {//必须fragment嵌套fragment才取ChildFragment
        return fragment.getChildFragmentManager();
    }

    return fragmentActivity != null ? fragmentActivity.getSupportFragmentManager() : null;
}
 
开发者ID:alibaba,项目名称:LuaViewPlayground,代码行数:18,代码来源:LVViewPager.java

示例2: findContainerById

import android.support.v4.app.Fragment; //导入方法依赖的package包/类
private ViewGroup findContainerById(Fragment fragment, int containerId) {
    if (fragment.getView() == null) return null;

    View container;
    Fragment parentFragment = fragment.getParentFragment();
    if (parentFragment != null) {
        if (parentFragment.getView() != null) {
            container = parentFragment.getView().findViewById(containerId);
        } else {
            container = findContainerById(parentFragment, containerId);
        }
    } else {
        container = mActivity.findViewById(containerId);
    }

    if (container instanceof ViewGroup) {
        return (ViewGroup) container;
    }

    return null;
}
 
开发者ID:wzx54321,项目名称:XinFramework,代码行数:22,代码来源:TransactionDelegate.java

示例3: getCallbacksOrThrow

import android.support.v4.app.Fragment; //导入方法依赖的package包/类
/**
 * Return the callbacks for a fragment or throw an exception.
 * <p/>
 * Inspired by: https://gist.github.com/keyboardr/5455206
 */
@SuppressWarnings("unchecked")
public static <T> T getCallbacksOrThrow(Fragment frag, Class<T> callbacks) {
    Fragment parent = frag.getParentFragment();

    if (parent != null && callbacks.isInstance(parent)) {
        return (T) parent;

    } else {
        FragmentActivity activity = frag.getActivity();
        if (activity != null && callbacks.isInstance(activity)) {
            return (T) activity;
        }
    }

    // We haven't actually failed a class cast thanks to the checks above, but that's the
    // idiomatic approach for this pattern with fragments.
    throw new ClassCastException("This fragment's activity or parent fragment must implement "
            + callbacks.getCanonicalName());
}
 
开发者ID:Datatellit,项目名称:xlight_android_native,代码行数:25,代码来源:EZ.java

示例4: onDestroy

import android.support.v4.app.Fragment; //导入方法依赖的package包/类
@Override
public void onDestroy() {
    super.onDestroy();

    if (mIsStateSaved) {
        mIsStateSaved = false;
        return;
    }

    boolean anyParentIsRemoving = false;
    Fragment parent = getParentFragment();
    while (!anyParentIsRemoving && parent != null) {
        anyParentIsRemoving = parent.isRemoving();
        parent = parent.getParentFragment();
    }

    if (isRemoving() || anyParentIsRemoving || getActivity().isFinishing()) {
        getMvpDelegate().onDestroy();
        if (presenterCallback != null) {
            presenterCallback.onDestroyPresenter();
        }
    }
}
 
开发者ID:ZherebtsovAlexandr,项目名称:MoxySandbox,代码行数:24,代码来源:BaseFragment.java

示例5: isDescendant

import android.support.v4.app.Fragment; //导入方法依赖的package包/类
/**
 * Returns true if the fragment is a descendant of our parent.
 */
private boolean isDescendant(Fragment fragment) {
  Fragment root = this.getParentFragmentUsingHint();
  while (fragment.getParentFragment() != null) {
    if (fragment.getParentFragment() == root) {
      return true;
    }
    fragment = fragment.getParentFragment();
  }
  return false;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:14,代码来源:SupportRequestManagerFragment.java

示例6: onDestroy

import android.support.v4.app.Fragment; //导入方法依赖的package包/类
@Override
public void onDestroy() {
	super.onDestroy();

	//We leave the screen and respectively all fragments will be destroyed
	if (getActivity().isFinishing()) {
		getMvpDelegate().onDestroy();
		return;
	}

	// When we rotate device isRemoving() return true for fragment placed in backstack
	// http://stackoverflow.com/questions/34649126/fragment-back-stack-and-isremoving
	if (mIsStateSaved) {
		mIsStateSaved = false;
		return;
	}

	// See https://github.com/Arello-Mobile/Moxy/issues/24
	boolean anyParentIsRemoving = false;
	Fragment parent = getParentFragment();
	while (!anyParentIsRemoving && parent != null) {
		anyParentIsRemoving = parent.isRemoving();
		parent = parent.getParentFragment();
	}

	if (isRemoving() || anyParentIsRemoving) {
		getMvpDelegate().onDestroy();
	}
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:30,代码来源:MvpAppCompatDialogFragment.java

示例7: compatChildFragmentExitAnim

import android.support.v4.app.Fragment; //导入方法依赖的package包/类
@Nullable
public Animation compatChildFragmentExitAnim(Fragment fragment) {
    if ((fragment.getTag() != null && fragment.getTag().startsWith("android:switcher:") && fragment.getUserVisibleHint()) ||
            (fragment.getParentFragment() != null && fragment.getParentFragment().isRemoving() && !fragment.isHidden())) {
        Animation animation = new Animation() {
        };
        animation.setDuration(exitAnim.getDuration());
        return animation;
    }
    return null;
}
 
开发者ID:wzx54321,项目名称:XinFramework,代码行数:12,代码来源:AnimatorHelper.java

示例8: onDestroy

import android.support.v4.app.Fragment; //导入方法依赖的package包/类
@Override
public void onDestroy() {
    super.onDestroy();

    //We leave the screen and respectively all fragments will be destroyed
    if (getActivity().isFinishing()) {
        getMvpDelegate().onDestroy();
        return;
    }

    // When we rotate device isRemoving() return true for fragment placed in backstack
    // http://stackoverflow.com/questions/34649126/fragment-back-stack-and-isremoving
    if (mIsStateSaved) {
        mIsStateSaved = false;
        return;
    }

    // See https://github.com/Arello-Mobile/Moxy/issues/24
    boolean anyParentIsRemoving = false;

    if (Build.VERSION.SDK_INT >= 17) {
        Fragment parent = getParentFragment();
        while (!anyParentIsRemoving && parent != null) {
            anyParentIsRemoving = parent.isRemoving();
            parent = parent.getParentFragment();
        }
    }

    if (isRemoving() || anyParentIsRemoving) {
        getMvpDelegate().onDestroy();
    }
}
 
开发者ID:dmitrikudrenko,项目名称:MDRXL,代码行数:33,代码来源:MvpCompatFragment.java

示例9: getContainerHost

import android.support.v4.app.Fragment; //导入方法依赖的package包/类
/**
 * Returns the container host.
 */
private Object getContainerHost() {
  Fragment parent = mFragment.getParentFragment();
  while (true) {
    if (parent == null) break;
    int containerViewId = Rigger.getRigger(parent).getContainerViewId();
    if (containerViewId > 0) break;
    parent = parent.getParentFragment();
  }
  if (parent == null) {
    return mActivity;
  }
  return parent;
}
 
开发者ID:JustKiddingBaby,项目名称:FragmentRigger,代码行数:17,代码来源:_FragmentRigger.java

示例10: setResult

import android.support.v4.app.Fragment; //导入方法依赖的package包/类
@Override
public void setResult(int resultCode, Bundle bundle) {
  if (mForResultTarget == null) {
    throwException(new UnSupportException("class " + this + " is not started by startFragmentForResult() method"));
  }
  //get the host object.
  Object host = mForResultTarget.obj;
  if (host == null) {
    Fragment startPuppet = mFragment.getParentFragment();
    while (true) {
      if (startPuppet == null) break;
      int containerViewId = Rigger.getRigger(startPuppet).getContainerViewId();
      if (containerViewId > 0) break;
      startPuppet = startPuppet.getParentFragment();
    }
    host = startPuppet == null ? mActivity : startPuppet;
  }
  //invoke the host#onFragmentResult method.
  Class<?> clazz = host.getClass();
  try {
    Method method = clazz.getMethod(RiggerConsts.METHOD_ON_FRAGMENT_RESULT, int.class, int.class, Bundle.class);
    method.invoke(host, mForResultTarget.arg1, resultCode, bundle);
  } catch (NoSuchMethodException ignored) {
    Logger
        .w(this, "Not found method " + RiggerConsts.METHOD_ON_FRAGMENT_RESULT + " in class " + clazz.getSimpleName());
  } catch (Exception e) {
    e.printStackTrace();
  }
}
 
开发者ID:JustKiddingBaby,项目名称:FragmentRigger,代码行数:30,代码来源:_FragmentRigger.java

示例11: isAnyParentOfFragmentRemoving

import android.support.v4.app.Fragment; //导入方法依赖的package包/类
private boolean isAnyParentOfFragmentRemoving() {
    boolean isAnyParentRemoving = false;

    Fragment parent = fragment.getParentFragment();
    while (!isAnyParentRemoving && parent != null) {
        isAnyParentRemoving = parent.isRemoving();
        parent = parent.getParentFragment();
    }
    return isAnyParentRemoving;
}
 
开发者ID:Jeevuz,项目名称:Outlast,代码行数:11,代码来源:FragmentOutlast.java

示例12: getCustomSettingsObject

import android.support.v4.app.Fragment; //导入方法依赖的package包/类
@Override
public Object getCustomSettingsObject() {
    if (globalSetting) {
        return null;
    }
    ISettingsFragmentParent parent = null;
    Fragment p = getParentFragment();
    while (p != null && parent == null) {
        if (p instanceof ISettingsFragmentParent) {
            parent = (ISettingsFragmentParent) p;
        } else {
            p = p.getParentFragment();
        }
    }

    if (parent == null && getActivity() instanceof ISettingsFragmentParent) {
        parent = (ISettingsFragmentParent) getActivity();
    }
    if (parent == null) {
        throw new RuntimeException(
                "You need to implement ISettingsFragmentParent in any of the SettingsFragment's parents (either parent fragment or parent activity), if you want to use custom settings and not "
                        + "global settings only!");
    }
    if (parent.getCustomSettingsObject() == null) {
        throw new RuntimeException("You need to provide a custom settings object in your ISettingsFragmentParent, if you want to use custom settings and not global settings only!");
    }
    return parent.getCustomSettingsObject();
}
 
开发者ID:MFlisar,项目名称:RecyclerViewPreferences,代码行数:29,代码来源:SettingsFragment.java

示例13: holderFragmentCreated

import android.support.v4.app.Fragment; //导入方法依赖的package包/类
void holderFragmentCreated(Fragment holderFragment) {
    Fragment parentFragment = holderFragment.getParentFragment();
    if (parentFragment != null) {
        mNotCommittedFragmentHolders.remove(parentFragment);
        parentFragment.getFragmentManager().unregisterFragmentLifecycleCallbacks(
                mParentDestroyedCallback);
    } else {
        mNotCommittedActivityHolders.remove(holderFragment.getActivity());
    }
}
 
开发者ID:JessYanCoding,项目名称:LifecycleModel,代码行数:11,代码来源:HolderFragment.java


注:本文中的android.support.v4.app.Fragment.getParentFragment方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。