Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 379
Dulaj Atapattu Avatar asked Aug 27 '16 16:08

Dulaj Atapattu


1 Answers

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

like image 93
Augusto Carmo Avatar answered Nov 14 '22 21:11

Augusto Carmo