I've been trying to use the TabHost. If you look it up at the Android API Reference, the entry on any of the associated Views (TabHost or TabWidget) send you to this tutorial. It begins by briefly mentioning that you can use the Tab set up to flip between views, or entire activities. Having said this, it chooses the latter, and steps you through a process that includes creating separate Activities and layout files for each tab.
Part way through this process, I found myself wondering why it's such an involved process. With so much Android UI defined by xml files, why do I have to create all these classes and then hook them up programmatically?
So I went looking for another example. A Google search for tab demos revealed an alternate example. Especially surprising is that this simpler example is also on the Android Developer site. In this approach, you lay out all the tab content in one xml file, and don't have to create any activities for each tab. Though you still have to create the tabs and connect them to their content in code, which seems un-Androidy. But overall it's a more straightforward approach if your tab set-up is relatively simple.
Really, I don't know why they link you to the more complex tutorial, but now you know there's an alternative. Also, whichever approach you use, here's some advice: When you put the TabHost and the FrameLayout in a LinearLayout, remember to set the orientation to vertical. It would be really embarrassing if you got that wrong and then couldn't figure out where the content went. I'm guessing.
No comments:
Post a Comment