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

推荐订阅源

Latest news
Latest news
T
Troy Hunt's Blog
V
Vulnerabilities – Threatpost
L
LINUX DO - 热门话题
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Simon Willison's Weblog
Simon Willison's Weblog
V
V2EX
博客园 - 司徒正美
B
Blog RSS Feed
AWS News Blog
AWS News Blog
MyScale Blog
MyScale Blog
Scott Helme
Scott Helme
Cisco Talos Blog
Cisco Talos Blog
Last Week in AI
Last Week in AI
NISL@THU
NISL@THU
博客园 - Franky
P
Proofpoint News Feed
博客园_首页
C
CERT Recently Published Vulnerability Notes
雷峰网
雷峰网
S
Schneier on Security
P
Proofpoint News Feed
Hugging Face - Blog
Hugging Face - Blog
G
GRAHAM CLULEY
博客园 - 三生石上(FineUI控件)
月光博客
月光博客
WordPress大学
WordPress大学
The Hacker News
The Hacker News
T
Threatpost
阮一峰的网络日志
阮一峰的网络日志
A
Arctic Wolf
Microsoft Azure Blog
Microsoft Azure Blog
T
The Exploit Database - CXSecurity.com
Engineering at Meta
Engineering at Meta
罗磊的独立博客
T
The Blog of Author Tim Ferriss
D
Darknet – Hacking Tools, Hacker News & Cyber Security
I
Intezer
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
K
Kaspersky official blog
SecWiki News
SecWiki News
云风的 BLOG
云风的 BLOG
美团技术团队
C
Cybersecurity and Infrastructure Security Agency CISA
博客园 - 【当耐特】
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Security Latest
Security Latest
C
Cyber Attacks, Cyber Crime and Cyber Security
B
Blog
S
Security Affairs

博客园 - 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");