我有10个哈希表,我需要将所有这10个哈希表存储到像数组一样的单个实例中。我想将选定的哈希表传递给另一个类/ Activity。 我怎样才能做到这一点?谢谢。
答案 0 :(得分:2)
创建你的课程:
public class Maps implements Parcelable {
Map[] mapArray = new Map[10];
public Map[] getMapArray() {
return mapArray;
}
public void setMapArray(Map[] mapArray) {
this.mapArray = mapArray;
}
@Override
public int describeContents() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
// TODO Auto-generated method stub
}
}
然后在活动中做下一件事:
Intent intent = new Intent(); // create intent that call your another activity
Maps maps = new Maps(); // create maps object.
maps.getMapArray(); // mark your selected maps
intent.putExtra("Maps", maps); // put key for your object
startActivity(intent);// start your another activity.
在另一项活动中,通过“地图”键获取此对象并使用它。
答案 1 :(得分:0)
我解决了我的问题如下
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.println(hm);
info.add(hm);
//循环结束