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(安卓)GPS定位问题
  2. Android(安卓)获取设备信息
  3. 2010.11.11———Android(安卓)TabHost选项卡组件
  4. android 获取图片信息 之 ExifInterface
  5. Android上的log,日志相关
  6. Android:获取APK签名信息 .
  7. 检测android的版本的办法
  8. Android中读取电话本Contacts联系人的所有电话号信息
  9. android 常用控件一览(从底层分析,为自定义控件做下小铺垫)

随机推荐

  1. linux下用git下载android任意模块源码
  2. AndroidPN的学习研究(一)环境建立
  3. RN调用Java原生方法步骤
  4. Kotlin for Android - 常用关键字
  5. 用 Python脚本生成 Android SALT 盐值
  6. 修改Android签名文件keystore作为eclipse
  7. Android之BroadcastReceiver的使用
  8. android使用aidl实现进程间通信的实例
  9. Android 利用程序实现GPS的打开或关闭
  10. Android(安卓)主题切换