Friday 18 January 2013

Tabs Demo through Intents


Screen Shots:






1.main.xml:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <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" >
    </FrameLayout>

</TabHost>



2.tab1.xml:

<?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"
    android:paddingTop="60dp" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="This is Tab 1 " />

    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:src="@drawable/one" />

</LinearLayout>

3.tab2.xml:

<?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"
    android:paddingTop="60dp" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="This is Tab 2 " />

    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:src="@drawable/two" />

</LinearLayout>


4.tab3.xml:

<?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"
    android:paddingTop="60dp" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="This is Tab 1 " />

    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:src="@drawable/three" />

</LinearLayout>


5.TabsDemoActivity:


package com.venkool.tabsdemo;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

public class TabsDemoActivity extends TabActivity {
     /** Called when the activity is first created. */
     @Override
     public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);

          TabHost tabHost = getTabHost();

          TabSpec spec1 = tabHost.newTabSpec("Tab1");
          spec1.setIndicator("Tab1");
          Intent intentTab1 = new Intent(this, Tab1Activity.class);
          spec1.setContent(intentTab1);

          TabSpec spec2 = tabHost.newTabSpec("Tab2");
          spec2.setIndicator("Tab2");
          Intent intentTab2 = new Intent(this, Tab2Activity.class);
          spec2.setContent(intentTab2);

          TabSpec spec3 = tabHost.newTabSpec("Tab3");
          spec3.setIndicator("Tab3");
          Intent intentTab3 = new Intent(this, Tab3Activity.class);
          spec3.setContent(intentTab3);

          tabHost.addTab(spec1);
          tabHost.addTab(spec2);
          tabHost.addTab(spec3);
     }
}


5.Tab1Activity:

package com.venkool.tabsdemo;

import android.app.Activity;
import android.os.Bundle;

public class Tab1Activity extends Activity {
     /** Called when the activity is first created. */
     @Override
     public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.tab1);

     }
}

6.Tab2Activity:
package com.venkool.tabsdemo;

import android.app.Activity;
import android.os.Bundle;

public class Tab2Activity extends Activity {
     /** Called when the activity is first created. */
     @Override
     public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.tab2);

     }
}


7.Tab3Activity:
package com.venkool.tabsdemo;

import android.app.Activity;
import android.os.Bundle;

public class Tab3Activity extends Activity {
     /** Called when the activity is first created. */
     @Override
     public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.tab3);

     }
}


8.manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.venkool.tabsdemo"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="10" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:label="@string/app_name"
            android:name=".TabsDemoActivity" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:label="@string/app_name"
            android:name=".Tab1Activity" />
        <activity
            android:label="@string/app_name"
            android:name=".Tab2Activity" />
        <activity
            android:label="@string/app_name"
            android:name=".Tab3Activity" />
    </application>

</manifest>




No comments:

Post a Comment