我在数组列表中有哈希表。
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/