TabHost tab and tabhost Tab

Source: Internet
Author: User

TabHost tab and tabhost Tab

Refer to: http://android.toolib.net/reference/android/widget/TabHost.html

TabHost = (TabHost) findViewById (android. R. id.Tabhost); // Obtain the TabHost object

TabHost. setup (); // initialize the TabHost component

LayoutInflater inflater = LayoutInflater.From(This); // Declare and instantiate a LayoutInflater object

// Begin to add more tab.

Inflater. inflate (R. layout.Tab1, TabHost. getTabContentView ());

Inflater. inflate (R. layout.Tab2, TabHost. getTabContentView ());

Inflater. inflate (R. layout.Tab3, TabHost. getTabContentView ());

Inflater. inflate (R. layout.Tab7, TabHost. getTabContentView ());

// Inflater. inflate (R. layout. tab4, tabHost. getTabContentView ());

TabHost. addTab (tabHost. newTabSpec ("tab01 ")

. SetIndicator ("SET ")

. SetContent (R. id.LinearLayout01); // Add the first tab

TabHost. addTab (tabHost. newTabSpec ("tab02 ")

. SetIndicator ("VID6X ")

. SetContent (R. id.LinearLayout02); // Add the second tab

TabHost. addTab (tabHost. newTabSpec ("tab03 ")

. SetIndicator ("VID2X-7X ")

. SetContent (R. id.LinearLayout03));

TabHost. addTab (tabHost. newTabSpec ("tab04 ")

. SetIndicator ("CCD-TEST ")

. SetContent (R. id.LinearLayout07));

// TabHost. addTab (tabHost. newTabSpec ("tab04 ")

//. SetIndicator ("DASHBOARD ")

//. SetContent (R. id. LinearLayout04 ));

/* Tab title height */

/* TabHost. getTabWidget (). getChildAt (0). getLayoutParams (). height = 75;

TabHost. getTabWidget (). getChildAt (1). getLayoutParams (). height = 75;

TabHost. getTabWidget (). getChildAt (2). getLayoutParams (). height = 75;

TabHost. getTabWidget (). getChildAt (3). getLayoutParams (). height = 75 ;*/

Switch tab event:

/* Run the following command when you switch from the VID6X or 2X-7X tab to another tab */

TabHost. setOnTabChangedListener (NewOnTabChangeListener (){

@ Override

PublicVoidOnTabChanged (String tabId ){

//TODOAuto-generated method stub

If(At6xdemo_flag = 1 )&&(! TabId. equals ("tab02 "))){

At6xdemo_flag = 0;

Toast.MakeText(GetApplicationContext (), "shut down 6x_demo", Toast.LENGTH_SHORT). Show ();

}

If(At27xdemo_flag = 1 )&&(! TabId. equals ("tab03 "))){

At27xdemo_flag = 0;

Toast.MakeText(GetApplicationContext (), "shut down 2x7x_demo", Toast.LENGTH_SHORT). Show ();

Demostart_flag = 0;

TextView text = (TextView) findViewById (R. id.StartText);

Text. setText ("start ");

Button start2 = (Button) findViewById (R. id.Start);

Start2.setBackgroundResource (R. drawable.Stoppi);

}

}

});

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.