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 一.在 ...
随机推荐
- 网络---中断套接字Socket
package socketpack_2; import java.awt.BorderLayout; import java.awt.EventQueue; import java.awt.even ...
- WinForm Control - DataGridView
http://blog.csdn.net/fangxing80/article/details/1561011 .NET 2.0 - WinForm Control - DataGridView 编程 ...
- navigationController.navigationBar.titleTextAttributes
navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor ...
- Core Data数据库迁移
一. Lightweight Migration i. 适合场景 Simple addition of a new attribute Removal of an attribute A non-op ...
- int型整数的数值范围
假设int型用两个字节表示对于有符号的整数,用补码表示的话,最高位是符号位,后面15位用来表示数据.1.正数,表示的范围为0000 0000 0000 0001-0111 1111 1111 1111 ...
- HTTP报头详解
HTTP头字段包括4类: general-header ; 通用报头 request-header ; 请求报头 response-header ; 响应报头 ...
- Linux系统下利用wget命令把整站下载做镜像网站
Linux系统下利用wget命令把整站下载做镜像网站 2011-05-28 18:13:01 | 1次阅读 | 评论:0 条 | itokit 在linux下完整的用wget命令整站采集网站做镜像 ...
- SEO优化的黑帽手法是否值得使用?
PR劫持 可能很多人也会听到说,什么网站权重越高越好,这也就是后面越来越多人都对谷歌的PR的宣传看的很重,自建站的都追求PR值,权重越高代表这个网站越受信任. 比如一个新站PR值为0,一个老站PR为6 ...
- Javascript学习笔记1 数论
1.Javascript不用担心内存的回收与对象的销毁! 2.Javascript有:±infinity.NaN全局变量表示 被0整除的±无穷 和 非数字.undefined和null表示 未定义 和 ...
- DevExpress GridView 自定义搜索按钮改为中文内容
首先将 GridControl 控件的搜索功能显示出来. http://www.cnblogs.com/DeepLearing/p/3887601.html 显示效果如下: 可以通过 GridLoca ...