Use the tab [Android entry 6]

Source: Internet
Author: User

========================================================== ====================================
1. Add a button to the main activity and use the button to jump to the tab.

Private button tabviewbutton = NULL; Public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); tabviewbutton = (button) findviewbyid (R. id. tabviewbutton); tabviewbutton. setonclicklistener (New tabviewbuttonlistener ();} // use the intent object to switch to class tabviewbuttonlistener implements onclicklistener {public void onclick (view arg0) in the activity of the tab) {// todo auto-generated method stub intent = new intent (); intent. setclass (tabviewtest. this, tabviewdemo. class); tabviewtest. this. startactivity (intent );}}

2. Create a tab layout file, tab_value.xml

<Framelayout xmlns: Android = "http://schemas.android.com/APK/RES/android" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent"> <textview Android: id = "@ + ID/view1" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: TEXT = "This is the first tab label"/> <textview Android: Id = "@ + ID/view2" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: text = "this is the second tab label"/> <textview Android: Id = "@ + ID/view3" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: text = "this is the third tab label"/> </framelayout>

3. Create a tab activity,
 
 

  protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub    super.onCreate(savedInstanceState);           setTitle("TabViewDemo");           TabHost tabHost = getTabHost();    LayoutInflater.from(this).inflate(R.layout.tab_demo,       tabHost.getTabContentView(),true);    tabHost.addTab(tabHost.newTabSpec("Tab1").setIndicator("Tab1").      setContent(R.id.view1));    tabHost.addTab(tabHost.newTabSpec("Tab2")setIndicator("Tab2").      setContent(R.id.view2));    tabHost.addTab(tabHost.newTabSpec("Tab3").setIndicator("Tab3").      setContent(R.id.view3)); }

4. register the tab activity in adroidmanifest. xml.

   <activity android:name=".TabViewDemo"                  android:label="@string/app_view">   </activity>

 

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.