Skip to content Skip to sidebar Skip to footer

Access Parent Fragment Method From Child Fragment

I'm trying to access from Map Fragment to myfunction() situed in the Parent Fragment Tabs. I tried the following line Tabs parentFragment = (Tabs) getParentFragment(); however pare

Solution 1:

onCreateView might be too early, try doing that onViewCreated, or onStart in the worst case.

Solution 2:

I would recommend you to put is after onCreateView and also check for the instance.

FragmentparentFragment= getParentFragment();

    if(parentFragment instanceof Tab) {
        ((Tab) parentFragment).myfunction();
    } 

Post a Comment for "Access Parent Fragment Method From Child Fragment"