eatwhatApp开发实战(十一)
2016-01-31 12:22
357 查看
之前我们实现了点击item项跳转activity,接下来我们再其基础上添加参数的传递。
在MainActivity里面的onItemClick()中:
String name = shopList.get(position).getName(); //意图 Intent it = new Intent(); //bundle对象 Bundle类用作携带数据,它类似于Map,用于存放key-value名值对形式的值。 Bundle mBundle = new Bundle(); mBundle.putString("name", name); //存放数据 it.putExtras(mBundle); //跳转activity it.setClass(MainActivity.this, ShopInfoActivity.class); //意图开启 startActivity(it);
在ShopInfoActivity中:
//声明变量 private TextView shopName;
在oncreat()方法中添加init():
init(); private void init(){ //初始化控件 shopName = (TextView) findViewById(R.id.tv_shop_name); //实现方法,获取MainActivity传过来的参数 shopName.setText(getData()); }
实现getData():
private String getData(){ Intent it = getIntent(); Bundle mBundle = it.getExtras(); String name = mBundle.getString("name"); return name; }
这样,点击跳转后就能获得商店名称。
相关文章推荐
- AppCan混合开发开发工具使用(一)
- Android-Day2-Property动画
- 从无到有写一个运维APP(二)
- iOS 安全攻防系列(四):分析二进制软件
- Android Fragment 真正的完全解析(下)
- Android Fragment 真正的完全解析(上)
- APPCAN页面图片自适应等比例显示
- IOS处女做--天气预报
- android-Providing Up Navigation,Providing Proper Back Navigation
- Android之自定义dialog对话框
- CC150 chapter 8 OOD object-oriented design
- iOS深度学习 - 多线程
- iOS常见算法(二分法 冒泡 选择 快排)
- iOS发布应用
- session application cookie
- android-Creating a Navigation Drawer
- Android之Android 自定义控件与属性
- iOS XCode启用/关闭Clang Warnings
- iOS Core Animation,图层的树状结构
- Unity3D跟随脚本