Duplicate ID, tag null, or parent id with another fragment for com.google.android.gms.maps.MapFragment

前端 未结 23 1893
-上瘾入骨i
-上瘾入骨i 2020-11-22 00:25

I have an application with three tabs.

Each tab has its own layout .xml file. The main.xml has its own map fragment. It\'s the one that shows up when the application

23条回答
  •  春和景丽
    2020-11-22 01:10

    Declare SupportMapFragment object globally

        private SupportMapFragment mapFragment;
    

    In onCreateView() method put below code

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

    In onDestroyView() put below code

    @Override
    public void onDestroyView() {
       super.onDestroyView();
    
        if (mapFragment != null)
            getFragmentManager().beginTransaction().remove(mapFragment).commit();
    }
    

    In your xml file put below code

     
    

    Above code solved my problem and it's working fine

提交回复
热议问题