MapFragment in Fragment, alternatives?

后端 未结 8 631
猫巷女王i
猫巷女王i 2020-12-08 10:32

I need your help... I work on it until 3 days. My app is working with fragments. One of these fragments has to display a map from the Google Maps V2 api for Android.

8条回答
  •  醉酒成梦
    2020-12-08 11:14

    Use SupportMapFragment to overcome this error:

    In fragment layout

    
    

    In Your Fragment onCreateView

    SupportMapFragment mapFragment = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.googleMap);
    
            if (mapFragment != null) {
                mapFragment.getMapAsync(this);
            }
    

    Since your layout is in the Fragment's layout, therefore the SupportMapFragment is the child layout of your fragment. Hence use getChildFragmentManager() which is Fragment's FragmentManager

提交回复
热议问题