Using TabActivity : TabActivity « UI « Android






Using TabActivity

  

package app.test;

import android.app.Activity;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.webkit.WebView;
import android.widget.TabHost;

class AndroidBrowser extends Activity {
  WebView browser;

  @Override
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    browser = new WebView(this);
    setContentView(browser);
    browser.loadUrl("http://www.android.com/");
  }
}

class CWBrowser extends Activity {
  WebView browser;

  @Override
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    browser = new WebView(this);
    setContentView(browser);
    browser.loadUrl("http://java2s.com");
  }
}

public class Test extends TabActivity {
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    TabHost host = getTabHost();

    host.addTab(host.newTabSpec("one").setIndicator("CW")
        .setContent(new Intent(this, CWBrowser.class)));
    host.addTab(host.newTabSpec("two").setIndicator("Android")
        .setContent(new Intent(this, AndroidBrowser.class)));
  }
}
//main.xml

<?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"
    >
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Hello World, IntentTabDemo"
    />
</LinearLayout>

   
    
  








Related examples in the same category

1.Thread demo