1. Example description
- Tabhost is a view container component provided by the Android system. It can display a group of child components by pageProgramMultiple activities are organized. To create a tabhost, you also need to introduce the tabwidget component and the tabhost. tabspec component. tabwidget represents the position of the tab, and tabhost. spec represents the content of each tab.
- In the layout file of this example, the ID of tabwidget must be set to "@ Android: ID/tabs", and the ID of framelayout must be set to "@ Android: ID/tabcontent ". In addition, if mainactivity does not inherit from tabactivityCodeIn, after you find the tabhost using the findviewbyid () method, you should first execute the setup () method to load the tabhost. If mainactivity inherits from tabactivity, the tabhost ID must be set to @ Android: ID/tabhost"
2. Running result
3. Core code
@ Overrideprotected void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); resources res = getresources (); tabhost host = (tabhost) findviewbyid (R. id. tabhost); host. setup (); tabspec spec; spec = partition 1); host. addtab (SPEC); spec = partition 2); host. addtab (SPEC); spec = partition 3); host. addtab (SPEC); host. setcurrenttab (1); host. setontabchangedlistener (New ontabchangelistener () {@ overridepublic void ontabchanged (string Tabid) {toast. maketext (mainactivity. this, Tabid, toast. length_short ). show ();}});
}
5. Video Explanation
Http://www.eyeandroid.com/thread-11497-1-1.html