问题描述
我想在活动之间发送带有哈希图的数组列表,但给我带有哈希图的空数组列表.
I want to send the arraylist with hashmap between activities but is give me null arraylist with hashmap.
发件人活动
ArrayList<HashMap<String,String>> childgame = new ArrayList<HashMap<String,String>>();
Intent ordernow= new Intent(CategoryActivity.this,OrderDetailActivity.class);
ordernow.putExtra("orderlist",childgame);
startActivity(ordernow);
接收器活动
Intent intent = getIntent();
Bundle bundle =intent.getExtras();
bundle.getSerializable("orderlist");
推荐答案
使用 putExtra(String, Serializable)
在 Intent 和 getSerializableExtra(String)
中传递值获取数据的方法.
Use putExtra(String, Serializable)
to pass the value in an Intent and getSerializableExtra(String)
method to retrieve the data.
ArrayList 实现了Serializable
ArrayList implements Serializable
http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html
你已经有了这个
ordernow.putExtra("orderlist",childgame);
获取列表
Intent intent = getIntent();
ArrayList<HashMap<String,String>> list = (ArrayList<HashMap<String, String>>) intent.getSerializableExtra("orderList");
public Serializable getSerializableExtra (String name)
在 API 级别 1 中添加
Added in API level 1
从意图中检索扩展数据.
Retrieve extended data from the intent.
参数
name 所需项目的名称.
name The name of the desired item.
退货
之前使用 putExtra() 添加的项目的值,如果未找到可序列化值,则为 null.
the value of an item that previously added with putExtra() or null if no Serializable value was found.
这篇关于在android中的活动之间传递带有hashmap的arraylist?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!