将自定义对象的parcelable添加到接口类

编程入门 行业动态 更新时间:2024-10-07 18:27:22
本文介绍了将自定义对象的parcelable添加到接口类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个自定义对象类,但是它是通过一个接口实现的,我该如何将parceable合并到其中. 我关注并搜索了parceable,但这仅适用于对象类. 例如:如何使我的自定义对象可拆分?

I have a custom object class but that is implemented through an inteface, how can i incorporate parceable in it. I have followed and searched about parceable, but it is only for object class. eg : How can I make my custom objects Parcelable?

我想将我的对象列表传递给android中的另一个活动.

I want to pass my object list to another activity in android.

代码:

public interface Projection { interface Job { @XBRead("./task") List<Task> getTasks(); @XBRead("./id") String getid(); @XBRead("./job_title") String getjob_title(); @XBRead("./job_description") String getjob_description(); @XBRead("./job_room") String getjob_room(); @XBRead("./status") String getstatus(); } interface Task { @XBRead("./task_id") String gettask_id(); @XBRead("./task_title") String gettask_title(); @XBRead("./task_description") String gettask_description(); @XBRead("./task_status") String gettask_status(); } @XBRead("/root/job") List<Job> getJobs(); }

推荐答案

您的自定义界面需要extend Parcelable.

实现自定义接口的类还需要实现Parcelable接口,包括CREATOR.

Classes that implement your custom interface need to also implement the Parcelable interface, including the CREATOR.

然后您可以像下面这样向Intent添加实现自定义接口的对象:

You can then add an object implementing your custom interface to an Intent like this:

intent.putExtra("thing", thing);

或添加包含以下对象的ArrayList:

or add an ArrayList containing these objects like this:

ArrayList<Thing> things; intent.putParcelableArrayListExtra("things", things);

在接收端,Activity可以像这样从Intent中提取对象:

On the receiving end, the Activity can extract the objects from the Intent like this:

Thing thing = intent.getParcelableExtra("thing");

ArrayList<Thing> things = intent.getParcelableArrayListExtra("things");

更多推荐

将自定义对象的parcelable添加到接口类

本文发布于:2023-11-11 08:37:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1577908.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   接口   对象   parcelable

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!