java - 如何将哈希表 Arraylist 获取到其他 Intent ?

标签 java android arraylist hashtable

我在数组列表中有哈希表。

 List<Hashtable<String, String>> info = new ArrayList<Hashtable<String, String>>();


 Hashtable<String, String> hm = new Hashtable<String, String>();
// Put elements to the map

hm.put("Read_Flag", s1);
hm.put("sms_received_id", s2);
hm.put("Sender_Id", s3);
hm.put("Sender_Name", s4);
hm.put("Patient_Name", s5);
hm.put("Received_Date", s6);
hm.put("Received_Text", s7);
hm.put("Received_Text_Full", s8);
hm.put("AttachmentFlag", s9);

// Get a set of the entries
Set<?> set = hm.entrySet();
// Get an iterator
Iterator<?> it = set.iterator();
// Display elements
while(it.hasNext()) {
Map.Entry me = (Map.Entry)it.next();
 // System.out.print(me.getKey() + ": ");
 // System.out.println(me.getValue());
}
//System.out.println(hm);

info.add(hm);

这里的信息包含我的哈希表。我怎样才能将这个“信息”对象放入其他类/Intent 中?

谢谢你...

最佳答案

创建一个扩展 Serializable 的类与 getter setter对于 List<Hashtable<String, String>> list

自定义.java

public class Custom implements Serializable{

    private static final long serialVersionUID = 4466821913603037341L;
    private List<Hashtable<String, String>> list;


    public List<Hashtable<String, String>> getList() {
        return list;
    }

    public void setList(List<Hashtable<String, String>> list) {
        this.list = list;
    }
}

传递到下一个 Activity。

List<Hashtable<String, String>> list = new ArrayList<Hashtable<String,String>>();

Custom custom = new Custom();
custom.setList(list);
intent.putExtra("myobj", custom);

在下一个 Activity 中检索

Intent intent = getIntent();
Custom custom = (Custom) intent.getSerializableExtra("myobj");
List<Hashtable<String, String>> list = custom.getList();

关于java - 如何将哈希表 Arraylist 获取到其他 Intent ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8725699/

相关文章:

java - 如何指定JDK的orbd.exe(对象请求代理守护进程)使用的端口范围?

java 采用具有相同方法名称的不同列表类型

java - Redis中不同的连接异常

机器人:windowLightStatusBar 真不工作

java - 使用Arraylist复制三维数组不安全?

java - HTTP 状态 400 – 错误请求 - Hibernate

java - 使用 Android 从 Scala 调用不同的 Java 父构造函数

java - 将 UI 元素链接到复杂链接项中的数据?

java - 使用ArrayList从数据库中检索数据并将其显示在JSP中

java - 如何从另一个类调用 ArrayList 方法?