Android, google maps fragment and viewpager - Error inflating class fragment

后端 未结 2 1423
独厮守ぢ
独厮守ぢ 2021-02-05 16:27

i\'m trying to use google maps v2 within viewpager (fragmentpager) in a fragment. It works fine if i swipe to fourth fragment (view pager), but if i go back to the first fragmen

相关标签:
2条回答
  • 2021-02-05 17:00
    public void onDestroyView() {
    super.onDestroyView();
    
    try {
        Fragment fragment = (getFragmentManager().findFragmentById(R.id.map_container));  
        FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
        ft.remove(fragment);
        ft.commit();
    } catch (Exception e) {
        e.printStackTrace();
    }
    

    }

    0 讨论(0)
  • 2021-02-05 17:06

    This worked for me.

    @Override
    public void onDestroyView() {
        // TODO Auto-generated method stub
        super.onDestroyView();
        try 
        {
            FragmentTransaction ft = getChildFragmentManager().beginTransaction();
            ft.remove(mapFragment);
            ft.commitAllowingStateLoss();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    0 讨论(0)
提交回复
热议问题