Skip to content

Instantly share code, notes, and snippets.

@nseidm1
Created March 12, 2014 19:49
Show Gist options
  • Select an option

  • Save nseidm1/9514890 to your computer and use it in GitHub Desktop.

Select an option

Save nseidm1/9514890 to your computer and use it in GitHub Desktop.
Get the parent fragment, of a child fragment, on 4.0+ devices using SDK fragments, not V4 Fragments.
public Fragment getParentFragmentTwo() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
return getParentFragment();
} else {
View view = getView();
while (view.getParent() != null) {
Fragment fragment = getFragmentManager().findFragmentByTag((String) view.getTag());
if (fragment != null)
return fragment;
view = (View) view.getParent();
}
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment