Android ApiDemos example resolution (194): Views-& gt; Tabs-& gt; Content

Source: Internet
Author: User

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.

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.