例子1:

 TabHost tabhost = (TabHost) findViewById(android.R.id.tabhost);
tabhost.setup(this.getLocalActivityManager());
Intent intent1 = new Intent(this,Second.class);
Bundle bundle1 = new Bundle();
bundle1.putStringArray("string", strings1);
bundle1.putFloatArray("values", values1);
intent1.putExtra("bundle",bundle1); Intent intent2 = new Intent(this,Second.class);
Bundle bundle2 = new Bundle();
bundle2.putStringArray("string", strings2);
bundle2.putFloatArray("values", values2);
intent2.putExtra("bundle",bundle2); Intent intent3 = new Intent(this,Second.class);
Bundle bundle3 = new Bundle();
bundle3.putStringArray("string", strings3);
bundle3.putFloatArray("values", values3);
intent3.putExtra("bundle",bundle3);

例子2:

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.RadioGroup;
import android.widget.TabHost;
import android.widget.RadioGroup.OnCheckedChangeListener; public class TabTest extends TabActivity{
private RadioGroup group;
private TabHost tabHost;
public static final String TAB_HOME="tabHome";
public static final String TAB_MES="tabMes";
public static final String TAB_TOUCH="tab_touch";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.maintabs);
group = (RadioGroup)findViewById(R.id.main_radio);
tabHost = getTabHost();
tabHost.addTab(tabHost.newTabSpec(TAB_HOME)
.setIndicator(TAB_HOME)
.setContent(new Intent(this,Main.class)));
tabHost.addTab(tabHost.newTabSpec(TAB_MES)
.setIndicator(TAB_MES)
.setContent(new Intent(this,Main2.class)));
tabHost.addTab(tabHost.newTabSpec(TAB_TOUCH)
.setIndicator(TAB_TOUCH)
.setContent(new Intent(this,TouchTest.class)));
group.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId) {
case R.id.radio_button0:
tabHost.setCurrentTabByTag(TAB_HOME);
break;
case R.id.radio_button1:
tabHost.setCurrentTabByTag(TAB_MES);
break;
case R.id.radio_button2:
tabHost.setCurrentTabByTag(TAB_TOUCH);
break; default:
break;
}
}
});
}
}

效果如如下:
首先解决tab_host 的actitvty的跳转刷新,
  public void
onCheckedChanged()方法进行group监控点击不同的事件响应,但是也只有点击不同的事件才会响应,这样问题就来了:比如同一个
actitvty进行 页面的缩放的的按钮就没有办法响应了。这里我是进行group立面的每一个RadioButton进行事件的处理
RadioButton.setOnClickListener().有人会说,不同的页面一旦显示一次当再次显示就不在刷新了,那么你可以这样设置一下
页面的跳转:

tabHost.addTab(tabHost
.newTabSpec(TAB_NEXT)
.setIndicator(TAB_NEXT)
.setContent(
new Intent(new Intent(this, DrawReportActivity.class))
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
));

看看和上面代码有何不同,不错就是这里:        .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)//就是这里起作用
下面解决进行页面传值的问题:
首先进行tab_host 向各个页面的传值:这个和普通的传值一样没有区别,

Intent intent_main = new Intent(this, DrawReportActivity.class);
Bundle bundle = new Bundle();
bundle.putInt("page", );
intent_main.putExtras(bundle);
tabHost.addTab(tabHost
.newTabSpec(TAB_LAST)
.setIndicator(TAB_LAST)
.setContent(
new Intent(intent_main)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));

在相应的DrawReportActivity获取这个数据就可以
其次进行不同actitvty 之间传值的说明:
比如在A.actitvty要求跳转到B.actitvty里面,这里这样进行的跳转:
TabTest.tabHost.setCurrentTabByTag(TabTest.TAB_LAST);
将上面代码里面的tabHost进行静态化,进行group的跳转过去,这样就显示需要跳转的页面了,传值呢?传值在这里可以采取进行广播的方法:

发送广播:

Intent it = new Intent(action1);
it.putExtra("url", et.getText().toString());
sendBroadcast(it);

在注册Androidmanifest.xml进行声明:

<receiver android:name="com.raq.tab.Broadcastreceiver">
<intent-filter>
<action android:name="Broadcast_page_num" />
</intent-filter>
</receiver>

得到相应的广播:

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent; public class Broadcastreceiver extends BroadcastReceiver {
public String url;
public void onReceive(Context context, Intent intent) {
url = intent.getExtras().getString("url");
}
}

进行传值,我觉得如果数据不是很多的话,完全可以写个静态类,进行存放一些数据,
这样跳转actitvty类得到时候进行同时的数据存放就可以了。

Android TabHost中Activity之间传递数据的更多相关文章

  1. 【Android 复习】 : Activity之间传递数据的几种方式

    在Android开发中,我们通常需要在不同的Activity之间传递数据,下面我们就来总结一下在Activity之间数据传递的几种方式. 1. 使用Intent来传递数据 Intent表示意图,很多时 ...

  2. 28、activity之间传递数据&批量传递数据

    import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android ...

  3. Android中Activity之间的数据传递

    在开发中,我们经常涌用到Activity,那么既然用到了Activity,就一定免不了在两个或者多个Activity之间传递数据.这里我们先说一说原理,然后在看看代码和例子. 情况A:我们需要从Act ...

  4. Android 笔记-Fragment 与 Activity之间传递数据

    Fragment 与 Activity之间传递数据有两种方法.一种是使用setArgument,一种是使用接口回调.以下先学习第一种方法. (1)使用setArgument方法: 为了便于理解,我在这 ...

  5. Activity之间传递数据的方式及常见问题总结

    Activity之间传递数据一般通过以下几种方式实现: 1. 通过intent传递数据 2. 通过Application 3. 使用单例 4. 静态成员变量.(可以考虑 WeakReferences) ...

  6. Activity之间传递数据或数据包Bundle,传递对象,对象序列化,对象实现Parcelable接口

    package com.gaojinhua.android.activitymsg; import android.content.Intent; import android.os.Bundle; ...

  7. 在activity之间传递数据

    在activity之间传递数据 一.简介 二.通过intent传递数据 1.在需要传数据的界面调用 intent.putExtra("data1", "我是fry&quo ...

  8. Android基础 -- Activity之间传递数据(bitmap和map对象)

    原文:http://blog.csdn.net/xueerfei008/article/details/23046341 做项目的时候需要用到在2个activity之间传递一些数据,之前做的都是些字符 ...

  9. Android学习总结——Activity之间传递参数

    核心内容:一.在 Activity 之间传递简单数据二.在 Activity 之间传递复杂数据 三.在 Activity 之间传递自定义值对象   软件环境:Android Studio   一.在 ...

随机推荐

  1. nodeJs事件之监听移除事件

    var EventEmitter=require('events').EventEmitter var life=new EventEmitter(); //comfort 求安慰,函数名: //fo ...

  2. 互联网产品设计常用文档类型-BRD、MRD、PRD、FSD (

    BRD Business Requirements Document,商业需求文档.这是产品声明周期中最早的问的文档,再早就应该是脑中的构思了,其内容涉及市场分析,销售策略,盈利预测等,通常是和老大们 ...

  3. C#委托详解(2):实现方式大全

    本系列文章将详细探讨C#中的委托,列举其主要的实现方式,并分析其在设计层面和编码层面带来的好处,最后会讨论其安全性和执行效率等. 接上篇(C#委托详解(1):什么是委托)介绍完什么是委托之后,来看看C ...

  4. android开发 根据Uri获取真实路径

    Uri uri = data.getData(); String[] proj = { MediaStore.Images.Media.DATA }; Cursor actualimagecursor ...

  5. Django RequestContext用法

    模版中的变量由context中的值来替换,如果在多个页面模版中含有相同的变量,比如:每个页面都需要{{user}},笨办法就是在每个页面的请求视图中都把user放到context中.   from d ...

  6. 看我是一只IT小小鸟有感

    当我看了<我是一只IT小小鸟>后,有许多的感想.就像许多作者一样,在接触计算机这个专业时都有许多的抱怨,对这个专业的不了解,对这个专业不知道从何学起有深深的无助感,对这个专业在未来的发展有 ...

  7. C++ Templates之模板元编程

    #ifndef POW3_H #define POW3_H template <int N> class Pow3 { public: enum{result = 3 * Pow3< ...

  8. poj 1986 Distance Queries LCA

    题目链接:http://poj.org/problem?id=1986 Farmer John's cows refused to run in his marathon since he chose ...

  9. 转载:百度原CTO李一男经典语录

    原文地址:http://www.cnblogs.com/marvin/archive/2010/01/20/1652088.html 百度原CTO李一男经典语录 [1]好好规划自己的路,不要跟着感觉走 ...

  10. URAL题解—不断跟新中

    1014:简单题,忘了0的情况可以是10,== 1219:找呀找规律,满足N*(N-1)/2+1=X;就是1 的情况了