I would like to have a header with a menu and to be able to only change the remaining part of the UI (i.e. header and menu are never reloaded, content is reloaded when the user select an option in the menu).
*******************************************
* header *
*******************************************
* option1 | option2 | option3 | option4...*
*******************************************
* *
* content to be updated *
* according to the option *
* selected in the menu *
* *
* *
*******************************************
I was going to use a ViewFlipper and add/remove layout for the content, but I’ve read that for complex content it might be better to use a Fragment. The only example I’ve seen is using TabHost and TabWidget, but I have my own menu that does not use TabWidget.
Can I use a ViewFlipper with one Fragment for each of the menu’s option?
Any help / suggestion / pointer welcome…
Thanks
You actually don’t need a ViewFlipper to do this.
The thing about Fragments is that you can replace an existing Fragment with a different one by simply calling a method to replace it. This works by using a (Linear, Relative, whichever you prefer but it doesn’t matter as far as I have noticed) layout and replacing it completely with a fragment.
Say you named the layout mainContent. It’s a LinearLayout embedded in a main layout file with your menu above it. You can then add a fragment (for example, OptionOne) to it by using the following method:
If you want to replace it by the content of OptionTwo, you can simply replace it by using this:
Note: I used a compatibility version of Fragments for this so your code might be different.
Also, to be able to use this method, you will need to change all of your current activities that you want to use like this to
Fragmentsas well.