使用intent传递map

来源:互联网 发布:centos git服务器配置 编辑:程序博客网 时间:2024/06/05 03:56

工具类

public class SerializableMap implements Serializable {    private HashMap<Integer, Boolean> map;    public HashMap<Integer, Boolean> getMap() {        return map;    }    public void setMap(HashMap<Integer, Boolean> map) {        this.map = map;    }}

使用

//需要传递的mapHashMap<Integer, Boolean> xbksmap = new HashMap<Integer, Boolean>();Intent intent1 = new Intent(DetailNotifiActivity2.this, XbksAlertActivity.class);                intent1.putExtra("flowname", flowname);                Log.i("gjw", "协办科室被点击");                //传递map                Bundle bundle1 = new Bundle();                SerializableMap tepmap1 = new SerializableMap();                tepmap1.setMap(xbksmap);                bundle1.putSerializable("tepmap", tepmap1);

接收map

HashMap<Integer, Boolean> isSelected= new HashMap<Integer, Boolean>();HashMap<Integer, Boolean> tempIsSelected= new HashMap<Integer, Boolean>();Intent intent = getIntent();Bundle bundle = getIntent().getExtras();SerializableMap serializableMap = (SerializableMap) bundle.get("tepmap"); //两个map相互赋值isSelected = serializableMap.getMap();isSelected.putAll(tempIsSelected);
原创粉丝点击