In my application, I have three tabs in the Action Bar.
Tab A : contains 2 fragments
Tab B : contains a WebViewFragment
Tab C : contains a WebViewFragment
Now, I use a global layout containing a LinearLayout.
I inflate the right layout in the LinearLayout according to the tab. But when I switch between B -> A, I get this error :
Caused by: java.lang.IllegalArgumentException: Binary XML file line #8: Duplicate id 0x7f0a0002, tag null, or parent id 0xffffffff with another fragment for com.myapp.CategoriesFragment
What is the best solution to handle this ?
I have tried to removeAllViews / reAdd the layout, but I get this Exception :
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
I think I haven’t choose the right solution.
Thanks for your answers
You can choose an inner container to hold the fragments
Refer to the sample layout below