2010.11.11———Android TabHost选项卡组件
参考:
http://www.cnblogs.com/keyindex/articles/1815074.html
其实 TabHost 有两种写法
1、继承Activity 用finViewById() 来得到TabHost
2、继承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;
@Override
protected 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);
}
}
分享到:
相关推荐
Android源码——android tabhost --android UI源码.zip
安卓Android源码——嵌套TabHost示例.zip
安卓Android源码——ViewPager和Tabhost结合,可滑动的tabhost.rar
安卓Android源码——ViewPager和Tabhost结合,可滑动的tabhost.zip
如果继承TabActivity,并且通过getTabHost()方法来获取TabHost,那么三者的ID必须是android.R.id.tabhost、android.R.id.tabs、android.R.id.tabcontent,如果继承Activity,可以通过findViewById来获取这三个组件,...
实现主流界面的选项卡布局。 这里新建3个的Intent用于Activity的切换 Intent tab1 = new Intent(this, TabOneActivity.class); Intent tab2 = new Intent(this, TabTwoActivity.class); Intent tab3 = new Intent...
(框架)Android例子源码——tabhost+activity+slidingMenu仿新浪微博布局.zip
安卓Android源码——tabhost--UI源码.zip
android 自定义实现TAB, 简化开发代码,提供效率
本文实例分析了Android TabHost选项卡标签图标始终不出现的解决方法。分享给大家供大家参考,具体如下: 在学习Android TabHost布局过程中,很多教程告诉我,这样来显示选项卡标签的图标和文字: TapSpec spec1 = ...
安卓Android源码——TabHost内嵌ActivityGroup界面管理源码.zip
Android实现tabHost控件自定义页签页面源码
配套博客 http://blog.csdn.net/shulianghan/article/details/18233209 对TabHost选项卡组件进行了详细解析.
Android源码——TabHost内嵌ActivityGroup界面管理源码_new_17.zip
androidTabhost的使用实例代码,仅供参考
android Tabhost使用Demo