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

推荐订阅源

V
Visual Studio Blog
I
InfoQ
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 【当耐特】
小众软件
小众软件
B
Blog RSS Feed
大猫的无限游戏
大猫的无限游戏
博客园 - 三生石上(FineUI控件)
Engineering at Meta
Engineering at Meta
人人都是产品经理
人人都是产品经理
Microsoft Security Blog
Microsoft Security Blog
Last Week in AI
Last Week in AI
H
Help Net Security
爱范儿
爱范儿
云风的 BLOG
云风的 BLOG
博客园 - 司徒正美
Y
Y Combinator Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Microsoft Azure Blog
Microsoft Azure Blog
L
LangChain Blog
WordPress大学
WordPress大学
GbyAI
GbyAI
Google DeepMind News
Google DeepMind News
腾讯CDC

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