In this example, you can use TabHost. TabContentFactory to dynamically create Content for the Tab page. You can use TabHost. TabContentFactory to dynamically create the Tab page Content as needed (after you select a page.
You can use TabActivity to implement the TabHost. TabContentFactory interface and the createTabContent method:
[Java]
Public class Tabs2 extends TabActivity
Implements TabHost. TabContentFactory {
@ Override
Protected void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
Final TabHost tabHost = getTabHost ();
TabHost. addTab (tabHost. newTabSpec ("tab1 ")
. SetIndicator ("tab1", getResources ()
. GetDrawable (R. drawable. star_big_on ))
. SetContent (this ));
TabHost. addTab (tabHost. newTabSpec ("tab2 ")
. SetIndicator ("tab2 ")
. SetContent (this ));
TabHost. addTab (tabHost. newTabSpec ("tab3 ")
. SetIndicator ("tab3 ")
. SetContent (this ));
}
/** {@ InheritDoc }*/
Public View createTabContent (String tag ){
Final TextView TV = new TextView (this );
TV. setText ("Content for tab with tag" + tag );
Return TV;
}
}
Public class Tabs2 extends TabActivity
Implements TabHost. TabContentFactory {
@ Override
Protected void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
Final TabHost tabHost = getTabHost ();
TabHost. addTab (tabHost. newTabSpec ("tab1 ")
. SetIndicator ("tab1", getResources ()
. GetDrawable (R. drawable. star_big_on ))
. SetContent (this ));
TabHost. addTab (tabHost. newTabSpec ("tab2 ")
. SetIndicator ("tab2 ")
. SetContent (this ));
TabHost. addTab (tabHost. newTabSpec ("tab3 ")
. SetIndicator ("tab3 ")
. SetContent (this ));
}
/** {@ InheritDoc }*/
Public View createTabContent (String tag ){
Final TextView TV = new TextView (this );
TV. setText ("Content for tab with tag" + tag );
Return TV;
}
}
In this example, a TextView is dynamically created for each page as the Content of the Tab.