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. Http请求中请求头Content-Type 为 form-data、x-www-form-urlencoded、raw、binary的区别

    参考文献:http://blog.csdn.net/ye1992/article/details/49998511

  2. c++中4个与类型转换相关的关键字分析

    static_cast reinterpret_cast dynamic_cast const_cast 1.**static_cast------运算符完成相关类型之间的转换** 使用场景:如在同一 ...

  3. 用winform程序来了解委托和事件

    一.浅谈委托 如果有个过winform 和webform 程序开发的小伙伴一定有个这样的感觉吧,点击Button直接就执行了那个方法,到此他是怎么实现了的呢,大家有考虑过没有? 回到正题,什么是委托呢 ...

  4. SqlServer -- 仅当使用了列列表并且 IDENTITY_INSERT 为 ON 时,才能为表'T_FM_AMTFLOW'中的标识列指定显式值。

    SET IDENTITY_INSERT TABLE_NAME ON; INSERT INTO TABLE_NAME(XXX, XXX,..., XXX) SELECT XXX, XXX,..., XX ...

  5. Microsoft VS 2008 过期解决方法破解方法

    Microsoft VS 2008 过期解决方法电脑上的Microsoft Visual Studio 2008 Team System 试用版提示离过期还有**天.于是百度,搜索结果大多是以下两种解 ...

  6. 10gRAC vip启动报错CRS-1006 CRS-0215

    为测试一个迁移方案,装了一套10g rac环境,可能是很久没有装过10g的RAC了,整个过程情况不断. 1.在把集群软件和数据库软件都装好之后,用crs_stat检测状态的时候,发现vip的状态不对, ...

  7. 金融计算器app的下载情况

    下图就是一个多月来的下载量情况~话不多说,直接上图哈. 数据来源:百度开发者平台

  8. POJ 1743 Musical Theme ——后缀数组

    [题目分析] 其实找最长的不重叠字串是很容易的,后缀数组+二分可以在nlogn的时间内解决. 但是转调是个棘手的事情. 其实只需要o(* ̄▽ ̄*)ブ差分就可以了. 背板题. [代码] #include ...

  9. js转盘抽奖

    这个是很简易的转盘,只用了html,css,js 通过css产生一个转盘上的指针,用js动态改变css中的transparent改变指针的角度.再添加一个背景图片类似于奖项的转盘 <!DOCTY ...

  10. linux 下使用配置文件

    最近鼓捣双机热备,写了些shell脚本 适用配置文件 以 ifbeat 为例,linux的标准的配置文件中等号两遍不能存在括号, 空格 或特殊符号可以用转衣服 ' \' beat=true prima ...