FragmentMap + ActionBar Tab

后端 未结 4 1380
忘了有多久
忘了有多久 2021-02-10 07:47

I\'ve been trying insert a MapView into an ActionBar Tab, but I wasn\'t able to solve the problem even googling.

Here is the Main

4条回答
  •  情歌与酒
    2021-02-10 08:29

    Solution is to start mapview in the main activity which should extend FragmentMapActivity. Then your fragment can implement the mapview by getting it from the main activity.

    Main activity:

        mMapView = new MapView(YourActivity.this, MAPS_KEY);
        mMapView.setClickable(true);
        Exchanger.mMapView = mMapView;
    

    Fragment:

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mMapView = Exchanger.mMapView;
        return mMapView;
    }
    
    @Override
    public void onDestroy() {
        if(mMapView != null) {
            NoSaveStateFrameLayout parentView = (NoSaveStateFrameLayout) mMapView.getParent();
            parentView.removeView(mMapView);
        }
        super.onDestroy();
    }
    

    Exchanger is a class with a static field with mapview in it.

提交回复
热议问题