android, Tutorial 029, UI, Tab

package com.powenko.Tutorial_UI_Tab;

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

public class Tutorial_UI_TabActivity extends TabActivity {
    /** Called when the activity is first created. */
	private TabHost tabHost;

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        tabHost = getTabHost();
      //  Intent mtab1 = new Intent(this,info.class);      s
        tabHost.addTab(tabHost.newTabSpec("tab1")
                .setIndicator("tab1", getResources().getDrawable(R.drawable.icon ))
                .setContent(new Intent(this, info.class)));

        tabHost.addTab(tabHost.newTabSpec("tab2")
                .setIndicator("tab2", getResources().getDrawable(R.drawable.icon))
                .setContent(new Intent(this, info.class)));

        tabHost.addTab(tabHost.newTabSpec("tab3")
                .setIndicator("tab3", getResources().getDrawable(R.drawable.icon))
                .setContent(new Intent(this, info.class)));

      tabHost.setCurrentTab(1);
      tabHost.setOnTabChangedListener(new OnTabChangeListener() {
  //        @Override
      public void onTabChanged(String arg0) {
        	  if (arg0.equals("tab3"))
        	  {
        		  tabHost.refreshDrawableState();
        	  }
      }

     });
    }
}

info.java

package com.powenko.Tutorial_UI_Tab;

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

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

    }

}

AndroidManifest.xml


<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.powenko.Tutorial_UI_Tab"

android:versionCode="1"

android:versionName="1.0">

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

&nbsp;

<application android:icon="@drawable/icon" android:label="@string/app_name">

<activity android:name=".Tutorial_UI_TabActivity"

android:label="@string/app_name">

<intent-filter>

<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />

</intent-filter>

</activity>

<activity android:name="info" ></activity>

</application>

</manifest>

sample code:

please download from here, “Tutorial_UI_TabActivity” ,
http://code.google.com/p/powenko-android-tutorial/

By admin-powenko

Dr. Powen Ko is a teacher and CEO on LoopTek LLC, and like to teaching. if you need to class, please let PowenKo know, he will love to service and sharing. LoopTek web site is www.looptek.com

Leave a Reply