Placing SupportMapFragment on DialogFragment

后端 未结 3 1908
野趣味
野趣味 2021-01-06 17:00

I\'m trying to add SupportMapFragment on DialogFragment, but it return error inflating class fragment. I cannot figure it out why its returned error infla

3条回答
  •  攒了一身酷
    2021-01-06 17:36

    I was facing problem while adding GoogleMapFragment inside DialogFragment and I have solved it as

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        if (Build.VERSION.SDK_INT < 21) {
            supportMapFragment = (SupportMapFragment) getActivity()
                    .getSupportFragmentManager().findFragmentById(R.id.mapDialog);
        } else {
            supportMapFragment = (SupportMapFragment) getActivity().getSupportFragmentManager()
                    .findFragmentById(R.id.mapDialog);
        }
        supportMapFragment.getMapAsync(this);
    }
    

    Override onDestroy() as

     @Override
    public void onDestroy() {
        super.onDestroy();
        if (null != supportMapFragment)
            getActivity().getSupportFragmentManager().beginTransaction()
                    .remove(supportMapFragment)
                    .commit();
    }
    

提交回复
热议问题