android--Label component (Tabhost) Small instance

Source: Internet
Author: User

The Tab.xml code is as follows:

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "Android:layout_width=" Fill_parent "android:layout_height=" fill_parent "android:orientation=" vertical "&G    T <linearlayout android:id= "@+id/tab_1" android:layout_width= "Wrap_content" android:layout_height= "W            Rap_content "android:orientation=" vertical "> <chronometer android:id=" @+id/mychronometer "            Android:layout_width= "Wrap_content" android:layout_height= "wrap_content"/> <button Android:id= "@+id/btnstart" android:layout_width= "wrap_content" android:layout_height= "Wrap_c Ontent "android:text=" Start timing "/> <button android:id=" @+id/btnstop "Android:lay Out_width= "Wrap_content" android:layout_height= "wrap_content" android:text= "Stop timing"/> <b Utton android:id= "@+id/btnbase "android:layout_width=" wrap_content "android:layout_height=" Wrap_content "an droid:text= "reset"/> <button android:id= "@+id/btnformat" android:layout_width= "Wrap_conte NT "android:layout_height=" Wrap_content "android:text=" formatted display "/> </LinearLayout> < LinearLayout android:id= "@+id/tab_2" android:layout_width= "wrap_content" android:layout_height= "Wrap_             Content "android:orientation=" vertical "> <analogclock android:layout_width=" wrap_content " android:layout_height= "Wrap_content"/> </LinearLayout> <linearlayout android:id= "@+id /tab_3 "android:layout_width=" wrap_content "android:layout_height=" Wrap_content "android:orientation=            "Horizontal" > <button android:id= "@+id/btnstart" android:layout_width= "Wrap_content" Android:layout_height= "Wrap_content" android:text= "Start timing"/> <button android:id= "@+id/btnstop" Android:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:text= "Stop Timing"/&G        T <button android:id= "@+id/btnbase" android:layout_width= "Wrap_content" Android:layout_h            eight= "Wrap_content" android:text= "reset"/> <button android:id= "@+id/btnformat" Android:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:text= "formatted display"/&gt    ; </LinearLayout></LinearLayout>

. Java code is as follows:

Package Org.lxh.demo;import Android.app.activity;import Android.app.tabactivity;import android.os.Bundle;import Android.os.systemclock;import Android.view.layoutinflater;import Android.view.view;import Android.view.view.onclicklistener;import Android.view.view.onfocuschangelistener;import Android.widget.Button; Import Android.widget.chronometer;import Android.widget.edittext;import Android.widget.tabhost;import Android.widget.tabhost.tabspec;import Android.widget.textview;public class Hello extends Tabactivity {// Inherit Tabhost class private Tabhost mytabhost;private int[] layres={r.id.tab_1,r.id.tab_2,r.id.tab_3};p ublic void OnCreate ( Bundle savedinstancestate) {super.oncreate (savedinstancestate);//life cycle Method This.mytabhost=super.gettabhost (); Layoutinflater.from (This). Inflate (R.layout.tab, This.myTabHost.getTabContentView (), true); for (int x=0;x< this.layres.length;x++) {tabspec mytab=mytabhost.newtabspec ("tab" +x); Mytab.setindicator ("label" +x); myTab.setContent (This.layres[x]); This.myTabHost.addTab (Mytab);}}} 

The results are as follows:


android--Label component (Tabhost) Small instance

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.