How to put Google Maps V2 on a Fragment using ViewPager

前端 未结 13 1928
攒了一身酷
攒了一身酷 2020-11-22 04:56

I am trying to do a tab layout same in Play Store. I got to display the tab layout using a fragments and viewpager from androidhive. However, I can\'t implement google maps

13条回答
  •  有刺的猬
    2020-11-22 05:38

    For the issue of getting a NullPointerException when we change the Tabs in a FragmentTabHost you just need to add this code to your class which has the TabHost. I mean the class where you initialize the tabs. This is the code :

    /**** Fix for error : Activity has been destroyed, when using Nested tabs 
     * We are actually detaching this tab fragment from the `ChildFragmentManager`
     * so that when this inner tab is viewed back then the fragment is attached again****/
    
    import java.lang.reflect.Field;
    
    @Override
    public void onDetach() {
        super.onDetach();
        try {
            Field childFragmentManager = Fragment.class.getDeclaredField("mChildFragmentManager");
            childFragmentManager.setAccessible(true);
            childFragmentManager.set(this, null);
        } catch (NoSuchFieldException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }
    

提交回复
热议问题