intent几种传值数组、对象、集合(Array,Object,List)
来源:互联网 发布:web网络考勤管理系统 编辑:程序博客网 时间:2024/06/01 15:37
http://www.cnblogs.com/userbibi/archive/2012/03/29/2423202.html
1.Array
private
ArrayList<String> checkList=
new
ArrayList<String>();
Intent intent=
new
Intent(mytext.
this
,show.
class
);
intent.putStringArrayListExtra(
"list"
, checkList);
startActivity(intent);
调用
Intent intent=
this
.getIntent();
ArrayList<String> list=intent.getStringArrayListExtra(
"list"
);
ArrayList<HashMap<String,String>> mylist=
new
ArrayList<HashMap< String,String>>();
///listview使用
ListView listview=(ListView)findViewById(R.id.MyListView);
for
(
int
i=
0
;i<list.size();i++)
{
HashMap<String,String> map=
new
HashMap<String,String>();
map.put(
"ItemTitle"
, list.get(i).toString());
mylist.add(map);
}
SimpleAdapter mSchedule=
new
SimpleAdapter(
this
,mylist,R.layout.show,
new
String[]{
"ItemTitle"
,
"ItemTitle"
},
new
int
[]{R.id.ItemTitle,R.id.ItemTitle});
listview.setAdapter(mSchedule);
2.对象、列表(object,List)
前面都一样,上遍文章已经讲解,这边补充一下,只讲一个Serializable的。。另一个Parcelable都差不多,各自实现各自的接口,调用的时候可以不用那么麻烦,真心不喜欢用Bundle ,挺多此一举的
改写
如果是List
List<Parking_Info> list=new ArrayList<Parking_Info>();//搜索结果集合
Intent intent=
new
Intent(LinkMap.
this
,MapList.
class
);
intent.putExtra(
"list"
, (Serializable)list);
startActivity(intent);
这边直接强制转化就行了,再接受的时候用(List<Parking_Info>) getIntent().getSerializable("list")就可以接受到List<Parking_Info>数据了
Listlist=(List)getIntent().getSerializableExtra("list");
调用起来倒也方便的
具体调用,遍历代码
@Override
public
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.listmain);
// List<Parking_Info> list=(List<Parking_Info>)getIntent().getSerializableExtra("list");
//创建适配器
SimpleAdapter adapter =
new
SimpleAdapter(
this
,getData(),R.layout.maplist,
new
String[]{
"name"
,
"kongwei"
,
"code"
,
"addr"
},
new
int
[]{R.id.name,R.id.kongwei,R.id.code,R.id.addr});
setListAdapter(adapter);
// ListView listview=(ListView)findViewById(R.id.SearchList);
// listview.setAdapter(adapter);
};
private
List<Map<String, Object>> getData() {
List<Map<String, Object>> list =
new
ArrayList<Map<String, Object>>();
//获取参数
List<Parking_Info> mylist=(List<Parking_Info>)getIntent().getSerializableExtra(
"list"
);
for
(
int
i=
0
;i<mylist.size();i++)
{
Map<String, Object> map =
new
HashMap<String, Object>();
map.put(
"name"
,mylist.get(i).getPrk_name());
map.put(
"kongwei"
,
"空位:"
+mylist.get(i).getKongwei());
map.put(
"code"
,
"收费:"
+ mylist.get(i).getCode());
map.put(
"addr"
,
"地址:"
+mylist.get(i).getPrk_addr());
list.add(map);
// Toast.makeText(this, mylist.get(5).getPrk_name(), Toast.LENGTH_LONG).show();
}
return
list;
}
0 0
- intent几种传值数组、对象、集合(Array,Object,List)
- intent几种传值数组、对象、集合(Array,Object,List)
- intent几种传值数组、对象、集合(Array,Object,List)
- 将List<Object[]>数组对象转换成List<HashMap<String, Object>>集合对象
- js中的Array对象转成字符串;java中的List转成String数组, List集合的合并
- intent传递对象以及list集合
- javascript类数组对象 array-like Object
- 顶点数组对象 VAO(Vertex Array Object)
- JS数组”(array)和“对象”(object)
- 对象object与数组array转化,互转
- Intent 传递List<Object>
- Intent传递List<Object>
- 数组和集合对象(-) Array学习
- 将JS对象或object对象转化为array数组
- Object Array List
- 集合框架_对象数组、集合(Collection)、集合(List)总结
- 集合框架_对象数组、集合(Collection)、集合(List)总结
- java中 set,list,array(集合与数组)相互转换
- springMVC学习笔记六(注解方式实现控制器)
- Homebrew, Ruby, and Rails on OS X 10.10
- hadoop知识之counter
- typedef和#define的用法与区别
- grep -v指令作用
- intent几种传值数组、对象、集合(Array,Object,List)
- 黑马程序员——java基础2 数据类型、流程控制、方法以及数组
- No repository found at http://m2eclipse.sonatype.org/sites/m2e.
- 鼠标悬浮上去 实现光晕效果
- ios 提示框 选择对话框 等待框 iphone,ipad
- springMVC学习笔记七(基于注解方式的控制器的数据验证,类型转换和格式化)
- [Unity3D学习]3D数学基础之向量
- C/C++:private私有继承
- Dao对数据库的操作进行封装