2010.11.11———Android TabHost选项卡组件

参考:http://www.cnblogs.com/keyindex/articles/1815074.html

其实 TabHost 有两种写法
1、继承Activity 用finViewById() 来得到TabHost2、继承TabActivity 用getTabHost() 来得到TabHost


我建议用第二种

因为我用第一种时 遇到个问题

当我的tab页指向另一个activity 即用intent来传递时 就会报个错误
java.lang.IllegalStateException: Did you forget to call 'public void setup(LocalActivityManager activityGroup)'?


很是郁闷 所以 我建议用第二种


步骤:

1、layout.xml 这个xml 因为是继承TabActivity 所以 有几个id是特定的 不能更改

<?xml version="1.0" encoding="utf-8"?><TabHost xmlns:android="http://schemas.android.com/apk/res/android"        android:id="@android:id/tabhost"         android:layout_width="fill_parent"        android:layout_height="fill_parent">         <TabWidget android:id="@android:id/tabs"            android:layout_width="fill_parent"            android:layout_height="wrap_content" />             <FrameLayout android:id="@android:id/tabcontent"            android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:paddingTop="68px">            <LinearLayout             android:id="@+id/gcxx"                android:orientation="vertical"                android:layout_width="fill_parent"                android:layout_height="wrap_content"               >                <TextView                 android:layout_width="fill_parent"                    android:layout_height="wrap_content"                    android:text="first tab" />            </LinearLayout>            <LinearLayout             android:id="@+id/sbjl"                android:orientation="vertical"                android:layout_width="fill_parent"                android:layout_height="fill_parent"                >              <TextView                 android:layout_width="wrap_content"                    android:layout_height="wrap_content"                    android:id="@+id/sbjl_upload_time"                     />                            </LinearLayout>        </FrameLayout></TabHost>



TabHost
TabWidget  tab头FrameLayout tab要显示的内容


这三个id是固定的 不能更改


2、Activity


package com.huitu.project;import android.app.TabActivity;import android.content.Intent;import android.os.Bundle;import android.widget.TabHost;import android.widget.TextView;public class QueryResultActivity extends TabActivity {private TextView tv_upload_time;private TextView tv_problem;private TextView tv_suggestion;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.query_result);tv_upload_time = (TextView)findViewById(R.id.sbjl_upload_time);tv_problem = (TextView)findViewById(R.id.sbjl_problem);tv_suggestion = (TextView)findViewById(R.id.sbjl_suggestion);Intent intent = this.getIntent();Bundle bundle = intent.getExtras();String GCBM = bundle.getString("GCBM");String problem = bundle.getString("problem");String suggestion = bundle.getString("suggestion");String upload_time = bundle.getString("upload_time");tv_upload_time.setText(upload_time);tv_problem.setText(problem);tv_suggestion.setText(suggestion);TabHost tabHost = getTabHost();//tabHost.setup(); //当继承Activity是 必须调用Intent gcxx = new Intent(this,GCXXActivity.class);gcxx.putExtra("GCBM", GCBM);tabHost.addTab(tabHost.newTabSpec("gcxx").setIndicator("工程信息").setContent(gcxx));tabHost.addTab(tabHost.newTabSpec("sbjl").setIndicator("上报记录").setContent(R.id.sbjl));tabHost.addTab(tabHost.newTabSpec("pic").setIndicator("图片信息").setContent(R.id.gcxx));tabHost.addTab(tabHost.newTabSpec("video").setIndicator("视频信息").setContent(R.id.sbjl));tabHost.setCurrentTab(2);}}


更多相关文章

  1. android 获取图片信息 之 ExifInterface
  2. Android上的log,日志相关
  3. Android:获取APK签名信息 .
  4. 检测android的版本的办法
  5. Android中读取电话本Contacts联系人的所有电话号信息
  6. android 常用控件一览(从底层分析,为自定义控件做下小铺垫)
  7. Android(安卓)中调试手段 打印函数调用栈信息
  8. Android(安卓)Styles and Themes
  9. Android之——JNI配置C语言打印Logcat信息

随机推荐

  1. Android: 显示系统模块加载以及调用流程
  2. Android推送通知指南
  3. Android:AsyncTask使用
  4. [置顶] 《Android 之美 从0到1 -- 高手之
  5. 谷歌 Android“开源“神话走向破灭
  6. android中异步加载网络图片
  7. Cheatsheet: 2012 10.01 ~ 10.07
  8. Android(安卓)SDK的默认目录导致的AVD启
  9. 关于Android 版本向下兼容
  10. 适用于Android的OpenSL ES指南-OpenSL ES