Android程序开发基础之——页面传值
2012-05-14 14:49
357 查看
Activity跳转与传值,主要是通过Intent类来连接多个Activity,通过Bundle类来传递数据。
示例代码如下:
1.1、使用intent.putExtra()方法赋值
1.2、在另一个页面获取传值
2.1、如果要传递的是一组数据的话,就要借助Bundle对象来传递数据了。
2.2获取传值的方法相同
示例代码如下:
1.1、使用intent.putExtra()方法赋值
public class menu extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.menu); ... // Button2 Button Btn2 = (Button) findViewById(R.id.button2); Btn2.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Intent intent = new Intent(menu.this, detail.class); intent.putExtra("flg", "list"); startActivity(intent); } }); ... }
1.2、在另一个页面获取传值
Bundle bundle = this.getIntent().getExtras(); String flg = bundle.getString("flg"); if (flg.equals("list")) { ... }
2.1、如果要传递的是一组数据的话,就要借助Bundle对象来传递数据了。
Bundle bundle = new Bundle(); bundle.putString("Name", "Jacker"); bundle.putString("Phone", "13590010101"); bundle.putBoolean("flg", true); intent.putExtras(bundle);
2.2获取传值的方法相同
Bundle bundle = this.getIntent().getExtras(); String name = bundle.getString("Name"); String phone = bundle.getString("Phone"); boolean flg = bundle.getBoolean("flg");
相关文章推荐
- Android程序开发基础之——页面传值
- Android程序开发基础之——页面布局
- Android程序开发0基础教程(一)
- Android开发之道(4)程序框架基础
- Android开发之道(4)程序框架基础
- 20155305 2016-2017-2 《Java程序设计》实验四 Android程序开发基础
- Android开发基础——真机测试错误,ADB启动不了,程序安装不了,the connection to adb is down,INSTALL_CANCELED_BY_USER...
- Android百度地图开发之开发第一个小应用,显示基础的地图页面
- Android 开发文档 程序基础——Affinities and new tasks
- android开发基础:Intent与Bundle的使用,实现页面跳转及信息传递
- 【Android基础】页面跳转与传值(Activity跳转与传值)
- Android基础】页面跳转与传值(Activity跳转与传值)
- 【Android基础】页面跳转与传值(Activity跳转与传值) .
- 【Android基础】页面跳转与传值(Activity跳转与传值)
- Android 程序开发——百度地图的使用(二) 基础地图
- 【Android基础】页面跳转与传值(Activity跳转与传值)
- Android 开发基础系列——程序崩溃之Unable to instantiate activity ComponentInfo
- Android 开发文档 之程序基础Application Fundamentals
- 微信小程序开发系列——4.小程序视图页面基础知识
- JAVA Eclipse如何开发Android的多页面程序