Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fragments Within Fragment Tabs

I'm building an application that requires Tabs, which are now deprecated. The dev guide says to use Fragments to replace the tabs instead. However, my application needs to have fragments within each tab, which means fragments inside fragments, which isn't allowed. Does anyone know of a possible work around for this?

like image 782
Lance Avatar asked Oct 24 '11 18:10

Lance


2 Answers

While the action bar support for tabs is designed to make it easy for the contents of a tab to be a fragment, that is not strictly required. You could use ViewFlipper, repeated calls to setContentView(), or something to arrange to change other stuff when the action bar tab is selected.

Prior to the native action bar (Android 1.x/2.x), either stick with classic tabs, or use something like Action Bar Sherlock to get an action bar and tabs.

like image 55
CommonsWare Avatar answered Oct 19 '22 11:10

CommonsWare


I fake tabs by having a "tabs" fragment across the top that contains multiple toggle buttons. Below that I have a merge view containing a separate fragment for each tab. I respond to taps on a toggle button by toggling the other buttons "off", showing the fragment for that "tab", and hiding the others.

like image 43
goto10 Avatar answered Oct 19 '22 13:10

goto10