In this example we have three tab as follows. you can move in the any tab at by clicking on the Tab. as follows
- First we design the XML layout as follows 12345678910111213141516
<?xmlversion="1.0"encoding="utf-8"?>android:id="@android:id/tabhost"android:layout_width="match_parent"android:layout_height="match_parent"><LinearLayoutandroid:id="@+id/linearLayout1"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><TabWidgetandroid:layout_width="match_parent"android:layout_height="wrap_content"android:id="@android:id/tabs"></TabWidget><FrameLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:id="@android:id/tabcontent"></FrameLayout></LinearLayout></TabHost> - Create the Activtity file for diffrent Tab Activities we have create three diffrent Activity : ActivityA, ActivityB, ActivityC as follows
- Than we Create Our main Activity as follows code..
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | package com.container;import android.app.Activity;import android.os.Bundle;import android.widget.TextView;public class ActivityA extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TextView tv=new TextView(this); tv.setText("I am in Tab A.."); setContentView(tv); // TODO Auto-generated method stub }} |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | package com.container;import android.app.Activity;import android.os.Bundle;import android.widget.TextView;public class ActivityB extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TextView tv=new TextView(this); tv.setText("I am in Tab B.."); setContentView(tv); // TODO Auto-generated method stub }} |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | package com.container;import android.app.Activity;import android.os.Bundle;import android.widget.TextView;public class ActivityC extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TextView tv=new TextView(this); tv.setText("I am in Tab C.."); setContentView(tv); // TODO Auto-generated method stub }} |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | package com.container;import android.app.TabActivity;import android.content.Intent;import android.content.res.Resources;import android.os.Bundle;import android.widget.TabHost;public class TabViewDemoActivity extends TabActivity { /** Called when the activity is first created. */ Resources res; TabHost tabHost; TabHost.TabSpec spec; Intent intent; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); res=getResources(); tabHost=getTabHost(); /**Create Tab A**/ intent=new Intent().setClass(this,ActivityA.class); spec=tabHost.newTabSpec("A") .setIndicator("A",res.getDrawable(R.drawable.ic_btn_speak_now)) .setContent(intent); tabHost.addTab(spec); /**Create Tab B**/ intent=new Intent().setClass(this,ActivityB.class); spec=tabHost.newTabSpec("B") .setIndicator("B",res.getDrawable(R.drawable.ic_btn_speak_now)) .setContent(intent); tabHost.addTab(spec); /**Create Tab C**/ intent=new Intent().setClass(this,ActivityC.class); spec=tabHost.newTabSpec("C") .setIndicator("C",res.getDrawable(R.drawable.ic_btn_speak_now)) .setContent(intent); tabHost.addTab(spec); }} |






