Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
187 views
in Technique[技术] by (71.8m points)

java - how to get Hash table Arraylist to other intent?

I have hashtbles in array list.

 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);

here info contains my hashtables. how can i get this "info" object into other class/intent?

Thank You...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Create a class that extends Serializable with getter setter for the List<Hashtable<String, String>> list

Custom.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;
    }
}

To pass to next Activity.

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

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

To retrieve in next Activity

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...