Using Google Maps inside a Fragment in Android

后端 未结 2 1258
迷失自我
迷失自我 2021-01-16 10:36

I am trying to load Google Maps inside fragment ,and I keep getting the same error regardless of what solution I am trying to implement. I have already gone though all of t

2条回答
  •  臣服心动
    2021-01-16 10:45

    You can do this as a normal fragment.

    public void replaceFragment(Fragment fragment, String fragmentTag){
                FragmentManager fragmentManager = getFragmentManager();
                FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
                fragmentTransaction.replace(R.id.container, fragment);
                fragmentTransaction.addToBackStack(fragmentTag);
                fragmentTransaction.commit();
            }
    
    private void initMap(){
            MapFragment mapFragment = MapFragment.newInstance();
            replaceFragment(mapFragment, fragmentTag);
            mapFragment.getMapAsync(this);
        }
    

提交回复
热议问题