Android TabHost中Activity之间传递数据
例子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之间传递数据的更多相关文章
- 【Android 复习】 : Activity之间传递数据的几种方式
在Android开发中,我们通常需要在不同的Activity之间传递数据,下面我们就来总结一下在Activity之间数据传递的几种方式. 1. 使用Intent来传递数据 Intent表示意图,很多时 ...
- 28、activity之间传递数据&批量传递数据
import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android ...
- Android中Activity之间的数据传递
在开发中,我们经常涌用到Activity,那么既然用到了Activity,就一定免不了在两个或者多个Activity之间传递数据.这里我们先说一说原理,然后在看看代码和例子. 情况A:我们需要从Act ...
- Android 笔记-Fragment 与 Activity之间传递数据
Fragment 与 Activity之间传递数据有两种方法.一种是使用setArgument,一种是使用接口回调.以下先学习第一种方法. (1)使用setArgument方法: 为了便于理解,我在这 ...
- Activity之间传递数据的方式及常见问题总结
Activity之间传递数据一般通过以下几种方式实现: 1. 通过intent传递数据 2. 通过Application 3. 使用单例 4. 静态成员变量.(可以考虑 WeakReferences) ...
- Activity之间传递数据或数据包Bundle,传递对象,对象序列化,对象实现Parcelable接口
package com.gaojinhua.android.activitymsg; import android.content.Intent; import android.os.Bundle; ...
- 在activity之间传递数据
在activity之间传递数据 一.简介 二.通过intent传递数据 1.在需要传数据的界面调用 intent.putExtra("data1", "我是fry&quo ...
- Android基础 -- Activity之间传递数据(bitmap和map对象)
原文:http://blog.csdn.net/xueerfei008/article/details/23046341 做项目的时候需要用到在2个activity之间传递一些数据,之前做的都是些字符 ...
- Android学习总结——Activity之间传递参数
核心内容:一.在 Activity 之间传递简单数据二.在 Activity 之间传递复杂数据 三.在 Activity 之间传递自定义值对象 软件环境:Android Studio 一.在 ...
随机推荐
- 使用itunes同步ios时丢失照片恢复
因没有备份,在使用同步功能后,发现照片被清空了,找到恢复方法,分享之! from:http://modmyi.com/forums/native-iphone-ipod-touch-app-discu ...
- Netsharp快速入门(之1) 介绍及需求说明
作者:秋时 杨昶 时间:2014-02-15 转载须说明出处 第一章 快速入门介绍 Netsharp是一个企业基础业务管理平台,介绍Netsharp分三个系列,分别是: 1. N ...
- 【环境】VS2013和MATLAB相互调用混合编程
Visual Studio和MATLAB混合编程,有两种方法: 1 MATLAB调用C程序: 2 VS调用MATLAB(目前见到的都是VS,其他编译器如codeblocks,或不提供这项功能): 前一 ...
- 在C#中使用GDAL创建Shape文件
这几天在项目中考虑使用GDAL,由于10年没有用过VC了,就在网上搜了下怎么样在C# 中使用GDAL,看到了http://blog.csdn.net/liminlu0314/article/detai ...
- BZOJ 4500: 矩阵 差分约束
题目链接: http://www.lydsy.com/JudgeOnline/problem.php?id=4500 题解: 从行向列建边,代表一个格子a[i][j],对每个顶点的所有操作可以合并在一 ...
- 【HDOJ】【3068】最长回文
Manacher算法 Manacher模板题…… //HDOJ 3068 #include<cstdio> #include<cstring> #include<cstd ...
- html公用库
<script src="http://lib.sinaapp.com/js/jquery/1.6/jquery.min.js" language="javascr ...
- TGL站长关于常见问题的回复
问题地址: http://www.thegrouplet.com/thread-112923-1-1.html 问题: 网站配有太多的模板是否影响网站加载速度 月光答复: wp不需要删除其他的模板,不 ...
- javascript document.write
在载人页面后,浏览器输出流自动关闭:在此之后,任何一个对当前页面进行操作的document.write()方法将打开—个新的输出流.它将清除当前页面内容(包括源文档的任何变量或值).document. ...
- Python中编码问题?
一.键盘输入 raw_input('请输入:'.decode('utf-8').encode('gbk'))raw_input(unicode('请输入:','utf-8').encode('gbk' ...