Android tab_Host页面跳转,传值,刷新等问题汇总

之前做了一个项目是关于Tab_Host的,现在完成了恰逢闲余写份总结,主要涉及里面遇到问题以及解决方案的。
(首先说明这份代码是在eoe 下载的,这里感谢分享的那位朋友,限于我的工程是公司的不能拿出来了,只能那这份原来的代码进行修改贴出来,欢迎拍砖);

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", 1);
                        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类得到时候进行同时的数据存放就可以了。

代码:这里

时间: 2024-08-28 22:07:32

Android tab_Host页面跳转,传值,刷新等问题汇总的相关文章

iOS 页面跳转传值,属性传值,代理传值,代码块传值,单例传值,通知传值

有时候我们在页面跳转的时候回传递相应的参数,如,你想把在第一个页面的文本框里的内容显示在第二个文本框中,或者你又想把第二个文本框中的内容改变之后到第一个页面的文本框中,所有,这个时候我们就要用到页面跳转传值 1.属性传值(正向传值) 属性传值是正向传值,只可以从前面一个页面传递到第二个页面,不可以从第二个页面传递到第一个页面 2.代理传值(逆向传值) 代理传值是逆向传值 代理传值步骤 代理传值 适用于 反向传值 1.1 创建协议 及协议方法 在反向传值的页面(SecondViewControll

PHP和JS页面跳转和刷新总结

PHP 页面跳转: // 只是跳转,所以一定要用die();或者exit;终止下一步操作; header('location:index.php'); exit; // 等待3秒,跳转并刷新 header('refresh:3; url=index.php'); JS 页面跳转: location.href='index.php'; // 后退+刷新(原表单的内容会丢失) location.go(-1); // 后退,不刷新(原表单的内容会保留) location.back(-1); // 刷新

Android项目页面跳转小Demo

近期在做Android项目的开发,刚刚接触会有非常多新东西须要学习,从环境的搭建到语言的熟悉都是须要一步步完毕的,接下来就拿一个页面跳转的样例来和大家分享一下自己的心得体会. 採用的架构: Demo中採用的是src/res/Manifest File架构.因为自己是新手.就依照这个传统的架构来做了. watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMDUwODgyNg==/font/5a6L5L2T/fontsize/400/fill/I0JBQ

怎样实现页面跳转和刷新

javascript中的location.href有很多种用法,主要如下. self.location.href="/url" 当前页面打开URL页面location.href="/url" 当前页面打开URL页面windows.location.href="/url" 当前页面打开URL页面,前面三个用法相同.this.location.href="/url" 当前页面打开URL页面parent.location.href=

PHP页面跳转传值的三种常见方式

一. POST传值 post传值是用于html的<form>表单跳转的方法,很方便使用.例如: ? 1 2 3 4 5 6 7  <html>  <form action='' method=''>  <input type='text' name='name1'>  <input type='hidden' name='name2' value='value'>  <input type='submit' value='提交'>  

页面跳转传值接收

遇到一个问题,有一个页面A,页面B和页面C都能跳转到页面A,然后页面B需要传值到页面A,执行函数取到后台数据,而从页面C进入就不需要,然后问题就来了 C1 = window.location.href.split("?")[1]; C2 = C1.split("=")[1]; 页面A的js这样写确实能取到从页面B传来的数据,但是从页面C跳转的页面A中的split没有定义,调整了几种接收方式都没有用,最后用的是判断页面来源网址来判断的函数是否执行 $(function

android 实现页面跳转及数据的传递和返回

1.实现效果: 原始界面:     ----传输数据----------> 填写数据后,点击计算后界面-----返回数据----->点击返回按钮后,回到上一个页面,依旧能够保留之前保持的数据                                   2.实现代码: a.两个布局文件: activity_main.xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout

5. window.location.href/replace/reload()--页面跳转+替换+刷新

1.window.location=url; window.location 对象用于获得当前页面的地址 (URL),并把浏览器重定向到新的页面. 一.最外层top跳转页面,适合用于iframe框架集 top.window.location.href("${pageContext.request.contextPath}/Login_goBack"); ===================================================================

window.location.href/replace/reload()/页面跳转+替换+刷新

一.最外层top跳转页面,适合用于iframe框架集 top.window.location.href("url"); ============================================================================================ 二.window.location.href和window.location.replace的区别 1.window.location.href="url":改变u