2

I have a fragment which contains a ViewPager. This ViewPager is obviously populated by other Fragments.

My question is, is there any way (something resembling getActivity()) for the Fragment in the ViewPager to get a reference to the host Fragment?

The Hungry Androider
  • 2,274
  • 5
  • 27
  • 52

1 Answers1

8

As long as it is API 17 or greater, you can use this:

getParentFragment()

It will return null if the fragment is inside of an activity, not another fragment.

See the documentation here.

Alex K
  • 8,269
  • 9
  • 39
  • 57