安卓初級教程(5):TabHost的思考
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的思考的更多相关文章
- 安卓初級教程(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 ...
- 安卓初級教程(3):ContentProvider的運用原理
package com.example.android.provider; import java.util.ArrayList; import java.util.HashMap; import j ...
- 安卓初級教程(2):SD創建file,儲存與讀寫的方法(1)
package com.sdmadik; import java.io.*; import android.app.Activity; import android.os.Bundle; import ...
- 安卓初級教程(1):@Database(1)
package com.example.android.db01; import android.app.Activity; import android.content.ContentValues; ...
- 安卓中級教程(3):ScrollView
以上是scrollview的圖例,可見srollview是一種滑動功能的控件,亦是非常常見的控件. 一般寫法如下: package com.mycompany.viewscroller; import ...
- 安卓中級教程(6):annotation的基本用法
package com.example.ele_me.activity; import android.annotation.SuppressLint; import android.app.Acti ...
- 安卓中級教程(1):@InjectView
package com.mycompany.hungry; import android.annotation.SuppressLint; import android.app.Activity; i ...
- 安卓中級教程(11):深入研究餓了麼的各個java檔運作關係(1)
package com.example.ele_me.activity; import android.annotation.SuppressLint; import android.app.Acti ...
- 安卓中級教程(10):@InjectView
package com.example.android.db01; import android.app.Activity; import android.content.ContentValues; ...
随机推荐
- DOCKER 为新启用的容器配置外网IP
网卡的配置文件存储在 /etc/sysconfig/network-scripts/ 目录下.每个网卡的详细内容将会以不同的名字存储,比如ifcfg-enp0s3. 让我们看下ifcfg-enp0s3 ...
- CentOS下yum安装LAMP
1. 用yum安装Apache,Mysql,PHP. 1.1安装Apache yum install httpd httpd-devel 安装完成后,用/etc/init.d/httpd start ...
- Java研发岗位面试归类B(附答案)
本文承接上文:Java研发岗位面试归类A(附答案): http://www.cnblogs.com/wp5719/p/5870243.html 答案自己网上找的,如有纰漏或错误,烦请指教. 七.数据库 ...
- Scrapy 爬虫 使用指南 完全教程
scrapy note command 全局命令: startproject :在 project_name 文件夹下创建一个名为 project_name 的Scrapy项目. scrapy sta ...
- 使用dd命令备份Linux分区
为了备份分区,开始使用的是Remastersys,但最终生成的iso文件仅有几十K,应该是软件bug,且此软件不再更新,后尝试使用Linux Respin,但github一直连接不上. 其实可以尝试使 ...
- 【干货】jsMind思维导图整合Easyui的右键菜单
原材料: 1.web版本的JavaScript思维导图(BSD开源协议)[戳这里去官网]. 2.easyui最新版[戳这里去官网]. 这里是原本的jsMind: 在线测试地址 :http://hizz ...
- HDU 5795 A Simple Nim 打表求SG函数的规律
A Simple Nim Problem Description Two players take turns picking candies from n heaps,the player wh ...
- IOS UIAppLocation 单例模式
UIApplocation * app=[UIApplocation shareapplocation]; UIAppLocation 只能被初始化一次. 一个程序中只能被创建一次,称为单例模式. 单 ...
- IE浏览器下一些图片无法显示的(在其他非ie浏览器能够显示)解决办法
因为要完成本学期老师布置得网页作业,做完的时候进行网页的兼容性测试,chrome和360都没有问题. ie下却有两个图片无法显示. 一般这种情况代码是没有什么问题的,一般是图片本身的问题, 当我用Ps ...
- 2016 Multi-University Training Contest 1 G. Rigid Frameworks
Rigid Frameworks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...