Tuesday, June 26, 2012


Want to many Activity made a lot of paging as shown below,

How to make it?

In fact, as long as the to use TabHost can simply reach First of all, we in the XML declaration a TabHost
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TabHost android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="wrap_content"> <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="5dp"> <TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="5dp" /> </LinearLayout> </TabHost> </LinearLayout> 
Above that is arranged to help you get the Tab
If you want to customize belong to own the Tab, you can look inside how the combination of

Again this xml into the inside of activity to present to remember here is inherited TabActivity
 public class TabHostDemoActivity extends TabActivity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } } 
So far, no way to show the effect of Tab (nonsense has not yet begun to write ah)

Then we joined a function addNewTab, used to increase the paging function has two parameters, a context other is to jump to another paging activity
  public void addNewTab(Context context, Class<?> cls, String tabName){ Resources res = getResources(); Intent intent = new Intent().setClass(this, cls); TabSpec spec = getTabHost().newTabSpec(tabName) .setIndicator(tabName, res.getDrawable(R.drawable.icon)) .setContent(intent); getTabHost().addTab(spec); } 
First, we have made to the current page TabHost, then add a tabTabSpec
Then we set the Tab icon and display the text, use setIndicator Finally, we want to join the Intent to join the Tab
Such by the Intent of the specified class will be ran into the inside of this Tab
Last call TabHost to this page added

At this time, we assume that you want to write three Tab
Therefore, we must join in the Project which three java files
Tab, TabTwo and TabThree
 public class Tab extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); } } 

 public class TabTwo extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); } } 

 public class TabThree extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); } } 

I remember here in the manifest inside
 <activity android:name="com.givemepass.tabhostdemo.Tab"></activity> <activity android:name="com.givemepass.tabhostdemo.TabTwo"></activity> <activity android:name="com.givemepass.tabhostdemo.TabThree"></activity> 

Back to the onCreate these three classes added to the tab
 @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); addNewTab(this,Tab.class,"TabOne"); addNewTab(this,TabTwo.class,"TabTwo"); addNewTab(this,TabThree.class,"TabThree"); getTabHost().setCurrentTab(0); getTabHost().requestFocus(); } 

And to set the Tab Showing a page, so the incoming setCurrentTab (0)
Execution to see you can see the beginning of the picture

Download
http://uploadingit.com/file/4fvqtydf46i8uezf/TabHostDemo.zip

Leave a Reply

Subscribe to Posts | Subscribe to Comments

- Copyright © .Hacking Cracking Tricks And Tutorials, Paid Scripts, Latest Exploits, 0Day Vulnerability, - Skyblue - Powered by Blogger - Designed by Johanes Djogan -