<android>tab tab

Source: Internet
Author: User

1. Inheriting tabactivity implementations

A) Use Framelayout in the layout file to list the tab component and the content component in the tab

b) activity to inherit tabactivity

c) Call Tabactivity's Gettabhost () method to get the Tabhost object

d) Create tab options with Tabhost

 Public classMainactivityextendstabactivity {@Override Public voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); /*requestwindowfeature (Window.feature_no_title); GetWindow (). SetFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FU Llscreen);*/tabhost th=Gettabhost (); Layoutinflater.from ( This). Inflate (R.layout.main, Th.gettabcontentview (),true); Th.addtab (Th.newtabspec (' All '). Setindicator ("All Call logs"). SetContent (r.id.textview01)); Th.addtab (Th.newtabspec ("OK"). Setindicator ("Received call"). SetContent (r.id.textview02)); Th.addtab (Th.newtabspec ("Cancel"). Setindicator ("Missed Call"). SetContent (r.id.textview03)); Th.setontabchangedlistener (NewOntabchangelistener () {@Override Public voidontabchanged (String tabId) {toast.maketext (mainactivity. This, TabId, Toast.length_long). Show ();    }                        }        ); }}

2. The tab content can also be specified by implementing an interface Tabhost.tabcontentfactory Createtabcontent method.

 Public classMainactivityextendsTabactivityImplementsTabhost.tabcontentfactory {/**Called when the activity is first created.*/@Override Public voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Tabhost th=Gettabhost (); Th.addtab (Th.newtabspec (' All '). Setindicator ("All call Logs"). SetContent ( This)); Th.addtab (Th.newtabspec ("OK"). Setindicator ("Received call"). SetContent ( This)); Th.addtab (Th.newtabspec ("Cancel"). Setindicator ("Missed Call"). SetContent ( This)); }    PublicView createtabcontent (String tag) {ListView LV=NewListView ( This); List<String> list =NewArraylist<string>();          List.add (tag); if(Tag.equals ("All") {List.add ("Tom"); List.add ("Kite"); List.add ("Rose"); }Else if(Tag.equals ("OK") {List.add ("Tom"); List.add ("Kite"); }Else{List.add ("Rose"); } Arrayadapter Adapter=NewArrayadapter ( This, Android.          r.layout.simple_list_item_checked, list);          Lv.setadapter (adapter); returnLV; }}

<android>tab 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.