将自定义对象传递给另一个片段

时间:2014-08-14 18:10:46

标签: java android android-fragments

我有一个班级

class Message
{
    public String message, sender;
    public Message (String msg, String from)
    {
        // check here that msg and from are not null. If so, use a default value or throw an NullPointerException
        message = msg;
        sender = from;
    }
    // Just a utility method for printing out the Message to System.out
    public String toString () { return sender+":"+message; }
}

我在主要活动中定义

Hashtable<String, ArrayList<Message>> table = new Hashtable<String, ArrayList<Message>>();

我想将此表变量传递给另一个片段。我该怎么做?

1 个答案:

答案 0 :(得分:2)

使用界面&amp;有自定义听众。

Communicating with Other Fragments