我有一个自定义对象类,但是它是通过一个接口实现的,我该如何将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添加到接口类
发布评论