惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
I
InfoQ
The Register - Security
The Register - Security
L
LangChain Blog
H
Help Net Security
The GitHub Blog
The GitHub Blog
S
Schneier on Security
博客园 - 【当耐特】
W
WeLiveSecurity
Attack and Defense Labs
Attack and Defense Labs
IT之家
IT之家
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Google DeepMind News
Google DeepMind News
The Cloudflare Blog
H
Heimdal Security Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Y
Y Combinator Blog
雷峰网
雷峰网
N
Netflix TechBlog - Medium
Security Archives - TechRepublic
Security Archives - TechRepublic
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
L
Lohrmann on Cybersecurity
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
T
The Exploit Database - CXSecurity.com
P
Privacy & Cybersecurity Law Blog
G
GRAHAM CLULEY
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
V
Visual Studio Blog
博客园 - 聂微东
PCI Perspectives
PCI Perspectives
Last Week in AI
Last Week in AI
A
Arctic Wolf
宝玉的分享
宝玉的分享
T
The Blog of Author Tim Ferriss
S
Secure Thoughts
T
Threat Research - Cisco Blogs
GbyAI
GbyAI
云风的 BLOG
云风的 BLOG
D
Darknet – Hacking Tools, Hacker News & Cyber Security
S
SegmentFault 最新的问题
SecWiki News
SecWiki News
月光博客
月光博客
大猫的无限游戏
大猫的无限游戏
Schneier on Security
Schneier on Security
P
Proofpoint News Feed
博客园 - Franky
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
AI
AI
Engineering at Meta
Engineering at Meta

博客园 - meil

C#下取得Exif中照片拍摄日期 DotNet中人民币符号的输出 BAT实现照片文件批量改名 Wicket中JQuery事件绑定失效的解决 软件开发中的完整测试所包括的环节UT、IT、ST、UAT Eclipse中SVN插件的安装方式 从mysql中导出单个表结构和数据 代码帝:一个月10万行代码 PHP中使用mktime获取时间戳的一个黑色幽默 Android开发调试工具ADB的使用 Android系统权限配置 Android程序开发基础之——页面布局 Android程序开发的环境配置 SQLServer2008 动态SQL实践 ASP.net中实现双表格同步缩放不变形 Javascript实现DIV滚动自动滚动到底部 SQL Server 日期格式转换示例大全 TinyMCE使用手册 LINQ中的OrderBy实现多字段升序、降序排序实现
Android程序开发基础之——页面传值
meil · 2012-05-14 · via 博客园 - meil

Activity跳转与传值,主要是通过Intent类来连接多个Activity,通过Bundle类来传递数据。

示例代码如下:

1.1、使用intent.putExtra()方法赋值

 1 public class menu extends Activity {
 2 
 3     @Override
 4     public void onCreate(Bundle savedInstanceState) {
 5         super.onCreate(savedInstanceState);
 6 
 7         setContentView(R.layout.menu);
 8 
 9         ...
10 
11         // Button2
12         Button Btn2 = (Button) findViewById(R.id.button2);
13 
14         Btn2.setOnClickListener(new OnClickListener() {
15 
16             @Override
17             public void onClick(View arg0) {
18 
19                 Intent intent = new Intent(menu.this, detail.class);
20                 intent.putExtra("flg", "list");
21                 startActivity(intent);
22             }
23         });
24 
25         ...
26         
27 
28     }

1.2、在另一个页面获取传值

1             Bundle bundle = this.getIntent().getExtras();
2             String flg = bundle.getString("flg");
3             if (flg.equals("list")) {
4                             ...
5             }

2.1、如果要传递的是一组数据的话,就要借助Bundle对象来传递数据了。

1         Bundle bundle = new Bundle();
2 
3         bundle.putString("Name", "Jacker");
4         bundle.putString("Phone", "13590010101");
5         bundle.putBoolean("flg", true);
6 
7         intent.putExtras(bundle);

2.2获取传值的方法相同

1              Bundle bundle = this.getIntent().getExtras();
2 
3              String name = bundle.getString("Name");
4              String phone = bundle.getString("Phone");
5              boolean flg = bundle.getBoolean("flg");