當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。