Android map in fragment nullpointer

后端 未结 2 1362
情书的邮戳
情书的邮戳 2021-01-26 08:11

In my project im trying to implementthis solution for managing a map in a dynamic added fragment.

public class MapFragment extends Fragment {
    private GoogleM         


        
2条回答
  •  清酒与你
    2021-01-26 08:52

    Since you are using nested fragments, you should use getChildFragmentManager()

    SupportMapFragment mapFragment = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map);
    

    And I recommend you to use getMapAsync method, because getMap is deprecated

    mapFragment.getMapAsync(new OnMapReadyCallback() {
        @Override
        public void onMapReady(GoogleMap googleMap) {
            setupMap(googleMap);
        }
    });
    

提交回复
热议问题