MapView.onMapReady never called in Fragment for load Google Map in MapView

后端 未结 6 824
野性不改
野性不改 2021-01-05 09:59

I\'ll try to show a map in my Android application on a fragment named RoeteFragment. If I debug my code I see that the method onMapReady is never c

6条回答
  •  盖世英雄少女心
    2021-01-05 10:50

    The map fragment is part of a layout you inflate to another fragment (let's call it parent). The inflated fragment becomes a child fragment NOT of the activity BUT of the parent fragment. You have to ask the parent fragment's child fragment manager:

    Note: Just extend simple fragment public class MapsFragments extends Fragment implements OnMapReadyCallback {} XML file

    
    

    and

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
    
        Log.d("check","onCreateView");
        // Inflate the layout for this fragment
        View view= inflater.inflate(R.layout.fragment_maps_fragments, container, false);
        // Gets the MapView from the XML layout and creates it
        final SupportMapFragment myMAPF = (SupportMapFragment) getChildFragmentManager()
                .findFragmentById(R.id.map);
        myMAPF.getMapAsync(this);
        return  view;
    }`
    

提交回复
热议问题