package com.myhost;

 import android.os.Bundle;
import android.view.LayoutInflater;
import android.widget.TabHost;
import android.app.TabActivity; public class TabhostActivity extends TabActivity { // Extend TabActivity class /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TabHost tabHost = this.getTabHost(); // The activity TabHost
LayoutInflater.from(this).inflate(R.layout.main,tabHost.getTabContentView(), true); tabHost.addTab(tabHost.newTabSpec("tab1")
.setIndicator("tab1", getResources()
.getDrawable(R.drawable.chartareaup_green))
.setContent(R.id.linearLayout1)); tabHost.addTab(tabHost.newTabSpec("tab2")
.setIndicator("tab2", getResources()
.getDrawable(R.drawable.home_yellow))
.setContent(R.id.linearLayout2)); tabHost.addTab(tabHost.newTabSpec("tab3")
.setIndicator("tab3", getResources()
.getDrawable(R.drawable.harddrivedownload_red))
.setContent(R.id.linearLayout3)); tabHost.addTab(tabHost.newTabSpec("tab4")
.setIndicator("tab4", getResources()
.getDrawable(R.drawable.shoppingcart_blue))
.setContent(R.id.linearLayout4));
}
}
 package net.weibo.ui;

 import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec; public class MainActivity extends TabActivity {
/** Called when the activity is first created. */
public TabHost mth;
public static final String TAB_HOME="HOME";
public static final String TAB_MSG="INFORMATION";
public static final String TAB_ABT="ABOUT";
public static final String TAB_SEH="SEARCH";
public static final String TAB_MORE="MORE"; public RadioGroup radioGroup; @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main); mth=this.getTabHost(); //mth 等於上一段第18行的寫法。 TabSpec ts1=mth.newTabSpec(TAB_HOME).setIndicator(TAB_HOME);
ts1.setContent(new Intent(MainActivity.this,FirstActivity.class));
mth.addTab(ts1); TabSpec ts2=mth.newTabSpec(TAB_MSG).setIndicator(TAB_MSG);
ts2.setContent(new Intent(MainActivity.this,SecondActivity.class));
mth.addTab(ts2); TabSpec ts3=mth.newTabSpec(TAB_ABT).setIndicator(TAB_ABT);
ts3.setContent(new Intent(MainActivity.this,ThirdActivity.class));
mth.addTab(ts3); TabSpec ts4=mth.newTabSpec(TAB_SEH).setIndicator(TAB_SEH);
ts4.setContent(new Intent(MainActivity.this,ForthActivity.class));
mth.addTab(ts4); TabSpec ts5=mth.newTabSpec(TAB_MORE).setIndicator(TAB_MORE);
ts5.setContent(new Intent(MainActivity.this,FifthActivity.class));
mth.addTab(ts5); this.radioGroup=(RadioGroup)findViewById(R.id.main_radio);
radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub switch(checkedId){
case R.id.radio_button0: mth.setCurrentTabByTag(TAB_HOME);
break;
case R.id.radio_button1: mth.setCurrentTabByTag(TAB_MSG);
break;
case R.id.radio_button2:
mth.setCurrentTabByTag(TAB_ABT);
break;
case R.id.radio_button3: mth.setCurrentTabByTag(TAB_SEH);
break;
case R.id.radio_button4: mth.setCurrentTabByTag(TAB_MORE);
break;
}
}
}); }
}

以上兩種寫法熟優熟劣?

安卓初級教程(5):TabHost的思考的更多相关文章

  1. 安卓初級教程(4):sqlite建立資料庫

    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 ...

  2. 安卓初級教程(3):ContentProvider的運用原理

    package com.example.android.provider; import java.util.ArrayList; import java.util.HashMap; import j ...

  3. 安卓初級教程(2):SD創建file,儲存與讀寫的方法(1)

    package com.sdmadik; import java.io.*; import android.app.Activity; import android.os.Bundle; import ...

  4. 安卓初級教程(1):@Database(1)

    package com.example.android.db01; import android.app.Activity; import android.content.ContentValues; ...

  5. 安卓中級教程(3):ScrollView

    以上是scrollview的圖例,可見srollview是一種滑動功能的控件,亦是非常常見的控件. 一般寫法如下: package com.mycompany.viewscroller; import ...

  6. 安卓中級教程(6):annotation的基本用法

    package com.example.ele_me.activity; import android.annotation.SuppressLint; import android.app.Acti ...

  7. 安卓中級教程(1):@InjectView

    package com.mycompany.hungry; import android.annotation.SuppressLint; import android.app.Activity; i ...

  8. 安卓中級教程(11):深入研究餓了麼的各個java檔運作關係(1)

    package com.example.ele_me.activity; import android.annotation.SuppressLint; import android.app.Acti ...

  9. 安卓中級教程(10):@InjectView

    package com.example.android.db01; import android.app.Activity; import android.content.ContentValues; ...

随机推荐

  1. opencv2.4更换为opencv3.1后,mxnet编译错误(libpng16.so.16)

    编译显示错误为: /usr/bin/ld: warning: libpng16.so.16, needed by /usr/local/lib/libopencv_imgcodecs.so, not ...

  2. 【Java EE 学习 57】【酒店会员管理系统之分页模板书写】

    分页一直是一个比较麻烦的问题,特别是在我做的这个系统中更是有大量的分页,为了应对该问题,特地写了一个模板以方便代码重用,该模板包括后台分页的模板.前端显示的模板两部分. 一.分页分析 分页需要三种类型 ...

  3. 【leetcode】Valid Palindrome

    题目简述: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ...

  4. ABP中单元测试的技巧:Mock和数据驱动

    (此文章同时发表在本人微信公众号"dotNET每日精华文章",欢迎右边二维码来关注.) 题记:虽然ABP为大家提供了测试的脚手架了,不过有些小技巧还是需要自己探索的. ASP.NE ...

  5. nodejs学习

    转自于网络: ubuntu 下面安装 vim 的问题 1.输入vim时,显示: 程序"vim"已包含在以下软件包中: * vim * vim-gnome * vim-tiny * ...

  6. ZoomEye 钟馗之眼 搜索工具 基于API

    #!/usr/bin/env python # -*- coding: utf-8 -*- # Author: f0rsaken import getopt import requests impor ...

  7. DNS枚举工具DNSenum

    DNS枚举工具DNSenum   DNSenum是一款非常强大的域名信息收集工具.它能够通过谷歌或者字典文件猜测可能存在的域名,并对一个网段进行反向查询.它不仅可以查询网站的主机地址信息.域名服务器. ...

  8. d-规则

    [问题描述]对任意给定的m(m∈N+)和n(n∈N+),满足m<n,构造一初始集合:P={x|m≤x≤n,x∈N+} (m,n≤100).现定义一种d规则如下:若存在a∈P,且存在K∈N+ ,K ...

  9. 转载:移动web开发规范

    本文来源:http://blog.csdn.net/joueu/article/details/44329825 以下是规范建议,均是日常在开发当中的的一些经验,仅供参考. 移动web开发规范 一.头 ...

  10. C语言题目复习前7章重点程序

    /** #include <stdio.h> #include <stdlib.h> int max(int n1, int n2) { return (n1 > n2) ...