通过与Android的活动之间HashMap的ArrayList中?Android、HashMap、ArrayList

2023-09-07 03:25:10 作者:每天都超可爱

我想与HashMap的发送活动之间的ArrayList的,但给我的HashMap的ArrayList空

发件人活动

 的ArrayList<&HashMap的LT;字符串,字符串>> childgame =新的ArrayList<&HashMap的LT;字符串,字符串>>();意图ordernow =新意图(CategoryActivity.this,OrderDetailActivity.class);ordernow.putExtra(orderlist,childgame);startActivity(ordernow); 

接收器的工作

 意向意图= getIntent();捆绑包= intent.getExtras();bundle.getSerializable(orderlist); 

解决方案 Java集合类 HashMap 基于JDK1.8

使用 putExtra(字符串,序列化)来传递一个意图和值 getSerializableExtra(字符串)方法来检索数据。

ArrayList的工具序列化

http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html

您已经有此

  ordernow.putExtra(orderlist,childgame); 

要获取列表

 意向意图= getIntent();ArrayList的<&HashMap的LT;字符串,字符串>>名单=(ArrayList的<&HashMap的LT;字符串,字符串>>)intent.getSerializableExtra(orderList); 

公共序列化getSerializableExtra(字符串名称)

在API级别1

从意图检索扩展的数据。

参数

命名所需的项目名称。

返回

如果没有可序列化的价值发现,美元,putExtra(pviously加入对$)或空项的值。

I want to send the arraylist with hashmap between activities but is give me null arraylist with hashmap.

Sender Activity

ArrayList<HashMap<String,String>> childgame = new ArrayList<HashMap<String,String>>(); 
Intent ordernow= new Intent(CategoryActivity.this,OrderDetailActivity.class);
ordernow.putExtra("orderlist",childgame);                                     
startActivity(ordernow);

Receiver Activity

Intent intent = getIntent();
Bundle bundle =intent.getExtras();
bundle.getSerializable("orderlist");

解决方案

Use putExtra(String, Serializable) to pass the value in an Intent and getSerializableExtra(String) method to retrieve the data.

ArrayList implements Serializable

http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html

You already have this

ordernow.putExtra("orderlist",childgame);

To get the list

Intent intent = getIntent();
ArrayList<HashMap<String,String>> list = (ArrayList<HashMap<String, String>>) intent.getSerializableExtra("orderList");   

public Serializable getSerializableExtra (String name)

Added in API level 1

Retrieve extended data from the intent.

Parameters

name The name of the desired item.

Returns

the value of an item that previously added with putExtra() or null if no Serializable value was found.