Activity传递参数——传递复杂数据(Bunble包)
一.新建一个空的工程
二.在主界面中添加一个按钮
三.新建一个空的activity,并命名为TheAty
四.修改MainActivity.java中的onCreate函数
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.btnStartAty).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this, TheAty.class);
// i.putExtra("data", "hello android"); Bundle b = new Bundle();
b.putString("name","jikexueyuan");
b.putInt("age",2);
i.putExtras(b);
startActivity(i); }
});
五.在TheAty的布局文件中给textView加上id号
<TextView android:text="@string/hello_world" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tv"/>
六.修改TheAty的源代码文件中的onCreate函数
private TextView tv;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_the_aty);
Intent i = getIntent(); Bundle data = i.getExtras();
tv = (TextView)findViewById(R.id.tv);
// tv.setText(i.getStringExtra("data"));
tv.setText(String.format("name=%s,age=%d",data.getString("name"),data.getInt("age")));
}
七.运行结果
ps:另一种传递Bundle的方式
//i.putExtras(b);
//在MainActivity.java中传递Bunble参数b
i.pushExtra("data",b);
//在TheAty.java中获取Bunble参数
Bunble data = i.getBunbleExtra("name");
Activity传递参数——传递复杂数据(Bunble包)的更多相关文章
- Activity传递参数——传递自定义数据类型
一.新建一个空的工程 二.在主界面中添加一个按钮 三.新建一个空的activity,并命名为TheAty 四.新建一个user类 //注意这里要实现Serializable,不然在传递参数时会出错 p ...
- Activity传递参数——传递简单数据
一.新建一个空的工程 二.在主界面中添加一个按钮 三.新建一个空的activity,并命名为TheAty 四.修改MainActivity.java中的onCreate函数 protected voi ...
- Html网页使用jQuery传递参数并获取Web API的数据
昨天Insus.NET有开始学习Web API,<ASP.NET MVC的Web Api的实练>http://www.cnblogs.com/insus/p/4334316.html .其 ...
- javascript页面间传递参数
1.通过URL传递参数 传递参数页 function setCity() { var str = document.getElementById("cityName"); if ( ...
- 分发系统介绍 expect脚本远程登录 expect脚本远程执行命令 expect脚本传递参数
expect脚本远程登录 yum install -y expect yum install -y tcl tclx tcl-devel 自动远程登录 #! /usr/bin/expect set h ...
- Activity之间传递参数(四)
--------siwuxie095 获取Activity的返回参数 1.首先修改两个布局文件,都修改为 LinearLayout 布局, 添加orientation属性为:vertical. (1) ...
- Activity之间传递参数(三)
------siwuxie095 传递值对象,即自定义的有数据类型的对象 1.首先 new 一个 class:User,用于创建自定义对象,同时右键 Generate 出 Constructor.se ...
- Activity之间传递参数(二)
------siwuxie095 传递数据包 1.传递数据包要用到Bundle,MainActivity.java中: package com.siwuxie095.sendargs; import ...
- 第一课android开发之在activity间传递参数
一.活动间简单参数传递:1.在布局中添加按钮,用<Button,用id设置id名称,id="@+id/这儿填写你要设置成的名称":用text设置按钮上显示的文字.text=& ...
随机推荐
- mysql与sql server参照对比学习mysql
mysql与sql server参照对比学习mysql 关键词:mysql语法.mysql基础 转自桦仔系列:http://www.cnblogs.com/lyhabc/p/3691555.html ...
- 006-shiro授权
一.授权流程 二.三种授权方式 2.1.编程式:通过写if/else 授权代码块完成: Subject subject = SecurityUtils.getSubject(); if(subject ...
- PL/SQL编程—控制语句
SQL> create or replace procedure sp_pro5(id_in varchar2) is v_sal mytest.salary%type; begin sel ...
- 236. Lowest Common Ancestor of a Binary Tree(最低公共祖先,难理解)
Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According ...
- 113. Path Sum II(求等于某个数的所有路径)
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given su ...
- C语言预处理命令之条件编译(#ifdef,#else,#endif,#if等)
转自:http://www.kuqin.com/language/20090806/66164.html 预处理过程扫描源代码,对其进行初步的转换,产生新的源代码提供给编译器.可见预处理过程先于编译器 ...
- Authentication token is no longer valid
Linux: Authentication token is no longer valid Problem: Authentication token is no longer valid; new ...
- JMeter接口测试和压力测试
JMeter接口测试和压力测试 JMeter可以做接口测试和压力测试.其中接口测试的简单操作包括做http脚本(发get/post请求.加cookie.加header.加权限认证.上传文件).做web ...
- HGVS,非HGVS形式的突变描述解释
NG_012232.1(NM_004006.1):c.93+1G>T: 在该转录本NM_004006.1外显子的第93个碱基的下1个碱基(属于内含子)G变为T. NG_012232.1(NM_0 ...
- 20145229吴姗珊《网络对抗》WEB基础实践
20145229吴姗珊<网络对抗>WEB基础实践 基础与实践 基础问题 1.什么是表单 表单是可以收集用户的信息和反馈意见,是网站管理者与浏览者之间沟通的桥梁. 一部分是HTML源代码用于 ...