Binary XML file line #10: Error inflating class fragment

后端 未结 2 1081
一向
一向 2021-01-27 13:53

In my project I use three tab to show three activities in single screen. Tab 1 - Map
Tab 2 - Games
Tab 3 - Imageflipper
When I select tabs in series like Map--->Ga

相关标签:
2条回答
  • 2021-01-27 14:18

    Use of this code in TopRatedfragment.java solve this problem:

    private static View view;
    
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (view != null) {
        ViewGroup parent = (ViewGroup) view.getParent();
        if (parent != null)
            parent.removeView(view);
    }
    try {
        view = inflater.inflate(R.layout.map, container, false);
    } catch (InflateException e) {
        /* map is already there, just return view as it is */
    }
    return view;
    }
    
    0 讨论(0)
  • 2021-01-27 14:22
    Caused by: java.lang.IllegalArgumentException: Binary XML file line #10: Duplicate id 0x7f050010, tag null, or parent id 0x0 with another fragment for com.google.android.gms.maps.SupportMapFragment
    

    you are absolutely right about the error bieng the xml, but only because you are creating a new fragment that android is already holding on the stack.

    instead of creating a new fragemtn you want to use a FragmentManager

    FragmentManager fman=getFragmentManager();
    
    fman.popBackStack();
    

    itll be something along these lines.... for more exact code....

    Fragment fragment = (Fragment) getFragmentManager().
                        .findFragmentById(R.your id here);
                    if (fragment != null && fragment.isInLayout()) {
    
                      fman.beginTransaction().show(fragment)
                    } else {
                      Fragment fragment = (Fragment) getFragmentManager().beginTransaction().add(your container-the file the error is coming from that holds all you fragments, fragment)
                          fman.beginTransaction().show(fragment)
    
                    }
    
    0 讨论(0)
提交回复
热议问题