Adding Tabs to the Tab Host Control

Now that you have retrieved your TabHost control and initialized it, you need to configure each tab using the addTab() method. This method takes a TabSpec parameter, which describes the tab contents. For example, the following code creates the All Scores tab:

TabSpec allScoresTab = host.newTabSpec("allTab");

allScoresTab.setIndicator(getResources().getString(R.string.all_scores), getResources().getDrawable(android.R.drawable.star_on)); allScoresTab.setContent(; host.addTab(allScoresTab);

The TabSpec control called allScoresTab has the tag reference "allTab". The actual tab label contains a TextView control and an icon (a star). Finally, you set the contents of the tab to ScrollViewAllScores, which wraps the TableLayout control called TableLayout_AllScores, defined in the scores.xml layout resource. Next, you add a second tab called friendsTab to the TabHost control. The second tab is implemented much like the first, only with different content (friend scores only, not all scores).

Was this article helpful?

0 0

Post a comment