例子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. Android -- NDK开发入门

    第一步,建立一个普通的Android项目HelloNDK,然后在与src同一级的目录下新建一个jni目录: 第二步,在jni目录下新建一个hello_ndk.c文件,代码如下: #include &l ...

  2. Android -- 经验分享(二)

    目录                                                                                   自定义两个View进行画图,让 ...

  3. 简单修改 MySQL 的 root 账号密码

    首先这是一篇非常非常初级的教程. 平时为了方便,经常是直接在网上下载 PHP + MySQL 的集成环境,但有一些 MySQL 的 root 账号是没有密码的(例如大名鼎鼎的 XAMPP 就是这样), ...

  4. c语言编程之二叉排序树

    二叉排序树,又称为二叉查找树.它是一颗空树,或者是具有下面的性质的二叉树: 1.若它的左子树不空,则左子树上所有节点的值均小于它的根结构的值: 2.若它的右子树不空,则右子树上所有节点的值均大于它的根 ...

  5. Invalid object name ‘sys.configurations’. (Microsoft SQL Server, Error: 208)

    http://blogs.msdn.com/b/ramaprasanna/archive/2009/09/16/invalid-object-name-sys-configurations-micro ...

  6. Java多jdk安装

    1.安装jdk 2.配置 1.安装(略) 2.配置 2.1 regedit 注册表修改,假定已经安装jdk1.6,现在更换为jdk1.7 注: 修改红色框中CurrentVersion为jdk1.7 ...

  7. 【BZOJ】【3613】【HEOI2014】南园满地堆轻絮

    思路题 考试结束前5.6min的时候想到……但是写挂了QAQ 其实就是(差值最大的逆序对之差+1)/2; 找逆序对其实维护一个max直接往过扫就可以了……因为逆序对是前面的数大于后面的数…… 正确性显 ...

  8. 在线编辑器 (UBB, FCK)

    这里主要说明一下:UBB UBB 使用类型HTML的语法.  UBB相对FCK的HTML方式, 安全性高. 用户不可以直接嵌入HTML代码.   UBB 在线编辑器(JS版): http://www. ...

  9. HTML5中表单验证的8种方法(转)

    在深人探讨表单验证之前,让我们先思考一下表单验证的真实含义.就其核心而言,表单验证是一套系统,它为终端用户检测无效的控件数据并标记这些错误.换言之,表单验证就是在表单提交服务器前对其进行一系列的检查并 ...

  10. 火狐和IE之间的7个JavaScript差异

    尽管 JavaScript 历史上使用冗长而令人生厌的代码块来标的特定浏览器的时期已经结束了,但是偶尔使用一些简单的代码块和对象检测来确保一些代码在用户机器上正常工作依然是必要的. 这篇文章中,我会略 ...