dulajra dulajra -4 years ago 272
Android Question

getSupportFragmentManager() inside a fragment inside a fragment

I have a navigation drawer activity and fragments are used for different items of the navigation drawer as usual. There is a tab layout in first item of navigation drawer. Tab layout has been implemented using viewpager. There is a map inside this viewpager.

What I want to do is call

SupportMapFragment mapFragment = (SupportMapFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.map);

But mapFragment is always null.

I spent more than 2 hours applying many methods but I couldn't succeed.

The problem here according to my knowledge is this. getActivity() method return the navigation drawer activity. getSupportFragmentManager() return the fragment attached to navigation drawer. But the map is not in that fragment. Map is inside the fragment within the view pager.

Can anyone suggest a method to achieve this?

Answer Source

use this getChildFragmentManager(); to get the FragmentManager inside a Fragment

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download