I am developping an app with an activity which switches between a few fragments. I was wondering if it is possible to have one of this fragment with tabs in the action bar, but not the other ones, knowing that, in general, the activity is tabbed and the tabs switch between fragments. In a nutshell, I want an activity with a few fragments, and one of this fragments should have tabs to browse between other fragments, is that possible?
Asked
Active
Viewed 143 times
2 Answers
2
Ofcourse it is possible, take a look around StackOverflow, there are a couple of questions already.
Instead of normal TabHost your should use FragmentTabHost and because you will have fragments inside a fragment, you will have to use getChildFragmentManager() instead of getFragmentManager().
-
Fine ! If I understand, the way of adding tabs to an activity is kind easy comparing to adding tabs to a fragment, isn't it? – Roman Panaget Aug 19 '15 at 13:22
-
Exactly, there are some minor differences on how to handle with fragments, but it should definitely work! – Marko Aug 19 '15 at 13:24
-
OK, just one last thing. When I add tabs to an activity I just call getActionBar() and then I use addTab() (with a little bit of more stuff), but I never used TabHost class so if you have a good tutorial for me please share it ! – Roman Panaget Aug 19 '15 at 13:32
-
I think it is not neccessary to use TabHost. If you already have an Acitivty with tabs, just continue from there. If you want to use TabHost, you can check this links [link1](http://www.learn-android-easily.com/2013/07/android-tabwidget-example.html), [link2](http://www.androidhive.info/2011/08/android-tab-layout-tutorial/). – Marko Aug 19 '15 at 14:07
-
1Thanks Marko! Good answer. – Roman Panaget Aug 19 '15 at 14:12
2
Nice post Marko! I was just typing up basically the same answer. Here is a link for the documentation on Nested Fragments hope that helps as well

velocity_distance
- 88
- 1
- 10