The example in this article is the Android tab control, which can reach the paging effect, making one screen as rich as possible and, of course, increasing the complexity of the development and then using it when necessary. The Android tab control is a bit odd to use and must be included and in the following order:
The Tabhost control->tabwidget (must be named tabs)->framelayout (must be named Tabcontent).
First, we'll post a screenshot of this example run:
Main.xml source code is as follows:
<?xml version= "1.0" encoding= "Utf-8"?> <tabhost android:layout_width= "Fill_parent"
Fill_parent "xmlns:android=" http://schemas.android.com/apk/res/android "android:id=" @android: Id/tabhost1 "> <tabwidget android:id= "@android: Id/tabs" android:layout_height= "wrap_content" android:layout_width= "Fill_ Parent "> </TabWidget> <framelayout android:id=" @android: Id/tabcontent "android:paddingtop=" 65px "Androi D:layout_width= "Fill_parent" android:layout_height= "fill_parent" > <linearlayout android:layout_height= "Wrap" _content "android:id=" @+id/tab1 "android:orientation=" vertical "android:layout_width=" fill_parent "> < EditText android:layout_height= "wrap_content" android:id= "@+id/edttab1" android:layout_width= "Fill_parent" > </EditText> <button android:layout_width= "wrap_content" android:layout_height= "Wrap_content" @+id/btntab1 "android:text=" TAB1 "></Button> </linearlayout> <linearlayout android:layout_height= "wrap_content" android:id= "@+id/tab2" android:layout_width= "Fill_parent" android:orientation= "Horizontal" > <edittext android:layout_height= "wrap_content" android:id= "@+id/edtTab2" Android:layout_width= "Wrap_content" android:layout_weight= "></EditText> <button android:layout_" Width= "Wrap_content" android:layout_height= "wrap_content" android:id= "@+id/btntab2" android:text= "TAB2" ></
Button></linearlayout> </FrameLayout> </TabHost>
Java program source code is as follows:
Package com.testtab;
Import android.app.TabActivity;
Import Android.os.Bundle;
Import Android.view.View;
Import Android.widget.Button;
Import Android.widget.EditText;
Import Android.widget.TabHost;
Import Android.widget.TabHost.TabSpec;
public class Testtab extends Tabactivity {//build Button btntab1,btntab2 based on tabactivity;
EditText edttab1,edttab2; /** called the activity is a.
* * @Override public void onCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
Tabhost tabs = Gettabhost ();
Set TAB1 Tabspec tab1 = Tabs.newtabspec ("Tab1"); Tab1.setindicator ("Tab1"); Sets the name of the Tab1 tab1.setcontent (R.ID.TAB1); Associated control Tabs.addtab (TAB1);
Add Tab1 btntab1= (Button) This.findviewbyid (R.ID.BTNTAB1);
edttab1= (EditText) This.findviewbyid (R.ID.EDTTAB1);
Btntab1.setonclicklistener (New Clickevent ());
Set TAB2 Tabspec tab2 = Tabs.newtabspec ("tab2"); tab2.seTindicator ("TaB2");
Tab2.setcontent (R.ID.TAB2);
Tabs.addtab (TAB2);
Btntab2= (Button) This.findviewbyid (R.ID.BTNTAB2);
Edttab2= (EditText) This.findviewbyid (R.ID.EDTTAB2);
Btntab2.setonclicklistener (New Clickevent ());
Tabs.setcurrenttab (0);
Class Clickevent implements View.onclicklistener {@Override public void OnClick (View v) {if (V==BTNTAB1) {
Edttab1.settext ("Tab1");
else if (V==BTNTAB2) {edttab2.settext ("tab2"); }
}
}
}