Tab tab Interface (1)

Source: Internet
Author: User

tab with a simple Application interface label is a different label for the interface component on the same page of the centralized interface layout file. and plan the code files that will be in the main class set. The advantage of this approach is that the number of files in the project is not added, but the tab interface component is assumed to be more personalized. Complex, concentrating them on the same file can cause difficulties in future program maintenance.

We have learned about the use of intent objects. Here we use the intent object to create the Tab tab interface. The new approach is actually based on a very easy concept, where each tab tab corresponds to a separate activity class. Therefore, the interface layout file and program code of different tabs are independent, so that the complexity of the interface layout files and program code can be reduced so that they are easy to read and maintain.


(1) To complete the Tab tab interface requires a Tabhost component. It is responsible for controlling the structure of the Entire Tab tab page. The Tabhost component consists of two components: the Tabwidget component and the Framelayout component. The Tabwidget component is responsible for controlling all tab labels, and the Framelayout component is responsible for displaying the interface components for each tab tab page.
(2) There are 2 ways to set up tab interface, one is to write the interface components within each tab page together in the same layout file. However, different <LinearLayout> tags separate the interface components within the tab page. Another way is to write the interface component within each tab page into a separate interface layout file, and then load it into the corresponding tab page using the intent method. This method requires the use of intent technology.

Here's a walkthrough of the first approach to pave the way for using intent objects:

<tabhost xmlns:android= "Http://schemas.android.com/apk.res/android" android:id= "@+id/tabhost" android:layout_width= "fill_parent" android:layout_height= "fill_parent" ><Tab Widget android:id = "@+id/tabs" android:layout_width= "fill_parent" android:layout_height= "fill_parent"/><!-- Tabwidget tag ID must be set to @android:id/tabs; The ID of the framelayout tag must be set to @android:id/tabcontent--><framelayout android:id= "@+id/tabcontent" Android:layout_ Width= "Fill_parent" android:layout_height= "fill_parent" ><linearlayout android:id= "@+id/tab1" Android:o rientaion= "vertical" android:layout_width= "fill_parent" android:layout_height= "Warp_content" android:paddingTop= " 70DP "><!--the first tab page of the interface component--></linearlayout><linearlayout android:id=" @+id/tab1 "Android:o rientaion= "vertical" android:layout_width= "fill_parent" android:layout_height= "Warp_content" android:paddingTop= " 70DP "><!--the Second tab page of the interface component--></linearlayout></framelayout></tabhost> 



Code:
Package Tw.android;import Java.util.calendar;import Android.app.*;import android.os.bundle;import Android.os.handler;import Android.view.view;import Android.widget.*;import Android.widget.tabhost.tabspec;public Class Tabpagedemo extends activity{//inherited classes are still activityprivate DatePicker mdatepik;private timepicker mtimepik;private TextView mtxtresult;private button Mbtnok;privte button mbtnok;//Create new Handler object Private Handler mhandler=new Handler (); **called when the activity is first created */@Overridepublic void onCreate (Bundle savedinstancestate) {super.oncreate ( Savedinstancestate); Setcontentview (R.layout.main); Setupviewcomponent ();} private void Setupviewcomponent () {//Gets the interface component from resource R and sets the property Tabhost tabhost= (tabhost) Findviewbyid (r.id.tabhost); Tabhost.setup (); Tabspec Spec=tabhost.newtabspec ("Tab1"); Spec.setcontent (R.ID.TAB1); Spec.setindicator ("Date and Time", GetResource (). Getdrawable (Android. R.drawable.ic_lock_idle_alarm), Tabhost.addtab (spec), Spec=tabhost.newtabspec ("tab2"); Spec.setindicator (" ProgressBar DEmo ", getresource (). Getdrawable (Android. R.drawable.ic_dialog_alert)); Spec.setcontent (R.ID.TAB2); Tabhost.addtab (spec); Tabhost.setcurrenttab (0);// The following is the original Setupviewcomponent () method in all the program code, program startup time loaded program Setcurrenttab (0), 0 represents the first tab page. 1 two tab page, others in turn}}






Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.

Tab tab Interface (1)

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.