SupportMapFragment.getmap() returns null

前端 未结 6 737
刺人心
刺人心 2020-11-30 11:49

I\'m trying to load SupportMapFragment dynamically in a fragment, here is my onCreateView() method:

@Override
    public View onCreateView(LayoutInflater inf         


        
6条回答
  •  生来不讨喜
    2020-11-30 12:46

    Just try using the following code. It worked for me.

    public class MapFragment extends SupportMapFragment {
    
        GoogleMap mapView;
        private Context context;
    
        @Override
        public void onCreate(Bundle arg0) {
            super.onCreate(arg0);
        }
    
        @Override
        public View onCreateView(LayoutInflater mInflater, ViewGroup arg1,
            Bundle arg2) {
            View view = super.onCreateView(mInflater, arg1, arg2);
    
            return view;
        }
    
        @Override
        public void onInflate(Activity arg0, AttributeSet arg1, Bundle arg2) {
            super.onInflate(arg0, arg1, arg2);
        }
    
        @Override
        public void onActivityCreated(Bundle savedInstanceState) {
            super.onActivityCreated(savedInstanceState);
            context = getActivity();
            mapView = getMap();
        }
    }
    

提交回复
热议问题