I have a map fragment inside another fragment. This was working before, but I think it messed up after I updated google play services library. What is wrong? fragment_map.xml:
<fragment
android:name="com.google.android.gms.maps.SupportMapFragment"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent" />
MapFragment:
GoogleMap map;
private static View view;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
if (view != null) {
ViewGroup parent = (ViewGroup) view.getParent();
if (parent != null)
parent.removeView(view);
}
try {
view = inflater.inflate(R.layout.fragment_map, container, false);
map = ((SupportMapFragment) getActivity()
.getSupportFragmentManager()
.findFragmentById(R.id.map))
.getMap(); // NullPointerException at this line
map.getUiSettings().setAllGesturesEnabled(true);
map.getUiSettings().setMyLocationButtonEnabled(false);
map.getUiSettings().setZoomControlsEnabled(true);
} catch (InflateException e) {
/* map is already there, just return view as it is */
}
return view;
}
I had to change
getActivity().getSupportFragmentManager()
to
getChildFragmentManager()
to get it working. No idea why it was working perfectly few days ago.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With