这是我的班级,我想将其列表发送到另一个活动。
public class PostComments {
public User from;
public String message;
public String createdTime;
public String like_count;
public Boolean user_likes;
}
这是User类,其对象在PostComments类中使用。
public class User extends BaseEntity{
public String photoUrl;
}
这是BaseEntity Class
public class BaseEntity {
public String Id;
public String Name;
}
如何将此对象从一个活动发送到另一个活动?
PostComments[] myData = ClickedPost.comments.data;
Intent PostCommentsActivity = new Intent(getActivity() , PostCommentsActivity.class);
getActivity().startActivity(PostCommentsActivity);
上面是打开PostCommentsActivity的代码,我想将myData对象发送到PostCommentsActivity。
我已经搜索了很多关于这个问题但是每个问题和教程都只解释了一个包含简单字符串,int或布尔变量的类。
答案 0 :(得分:1)
试试吧:
ArrayList<PostComments> comments = new ArrayList<MainActivity.PostComments>();
comments.add(...) //Add your list data here
Intent intent = new Intent(getActivity() , PostCommentsActivity.class);
intent.putExtra("list_comments", comments);
getActivity().startActivity(intent);
将您的PostComments课程编辑为:
public class PostComments implements Serializable {
public String message;
public String createdTime;
public String like_count;
public Boolean user_likes;
}
在PostCommentsActivity中,获取bundle以获取列表注释。