We all know getParentFragment of Fragment is introduced in API 17.
So what if we want to get parent fragment in API 16 and below (Considering that I use native Fragment with support FragmentStatePagerAdapter and have no problem with nested fragments)
Is there any better way than mine?
In parent:
public class ParentFragment extends Fragment {
public static ParentFragment StaticThis;
...
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
StaticThis = this;
...
}
In child:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
parentFragment = (ParentFragment) getParentFragment();
else
parentFragment = ParentFragment.StaticThis;