Android的 - 如何通过的HashMap<字符串,字符串>活动之间? [英] Android - How to pass HashMap<String,String> between activities?

查看:120
本文介绍了Android的 - 如何通过的HashMap<字符串,字符串>活动之间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过详细信息的HashMap到另一个活动?

 的HashMap<字符串,字符串>详细=新的HashMap<字符串,字符串>();
detail.add(姓名,帕雷什);
detail.add(姓,mayani);
detail.add(手机,99999);
......
......
 

解决方案

这是pretty的简单,所有集合对象实现Serializable接口(SP?)接口,这意味着它们可以在被作为附加功能意图

使用 putExtra(字符串键,序列化OBJ)插入的HashMap 和其他活性的研究使用 getIntent()。getSerializableExtra(字符串键),您需要将返回值转换为的HashMap 虽然

How to pass the detail HashMap to another Activity?

HashMap<String,String> detail = new HashMap<String, String>();
detail.add("name","paresh");
detail.add("surname","mayani");
detail.add("phone","99999");
......
......

解决方案

This is pretty simple, All Collections objects implement Serializable (sp?) interface which means they can be passed as Extras inside Intent

Use putExtra(String key, Serializable obj) to insert the HashMap and on the other acitivity use getIntent().getSerializableExtra(String key), You will need to Cast the return value as a HashMap though.

这篇关于Android的 - 如何通过的HashMap&LT;字符串,字符串&GT;活动之间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆