Indeed, this is the official approach.
http://developer.android.com/training/implementing-navigation/nav-drawer.html#ListItemClicks
Question
I use a SlidingMenu
to display a Side Drawer (instead of tabs). Now, inside the SlidingMenuFragment
, there is a ListView
with 6 rows, each one being an equivalent of a tab.
When the user touches one of the 6 items, the content view should update the Framelayout
with the corresponding Fragment for that item.
Ex:
When you select cats, the SlidingMenu
disappears and the CatsFragment
should show up on the screen, replacing the old fragment present there.
Question: What is the best way to store all the fragments that are going to be swapped to and from the content view, also taking into consideration orientation change ? Instantiate a new Fragment every time I need to swap it ? Or instantiate all of them, save them in list then use them from there ?
What I did:
To store the list of fragments for easy access, I use an ArrayList. I save this ArrayList in onRetainCustomNonConfiguration() and retrieve it after orientation change, so that I don't instantiate another list of fragments, but I don't believe this is a good idea.
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.activity_main_framelayout, mFragmentsList.get(mCurrentFragmentPosition))
.commit();
La solution
Indeed, this is the official approach.
http://developer.android.com/training/implementing-navigation/nav-drawer.html#ListItemClicks