简体   繁体   English

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

[英]Pass custom object to another fragment

I have a class 我有一堂课

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

I am defining in main activity 我在主要活动中定义

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

I want to pass this table variable to another fragment.How can I do this ? 我想将此表变量传递给另一个片段。如何执行此操作?

Use Interface & have custom listeners. 使用接口并具有自定义侦听器。

Communicating with Other Fragments 与其他片段通信

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM