问题
I have a class TableMetaAttrs:
public class TableMetaAttrs implements Parcelable
{
private Integer id;
private String name;
private String value;
private Tables table;
...
How do i implement Parcelable on table field? Class Tables also implements Parcelable.
回答1:
You have to make the Tables
class implements Parcelable
as well.
That way whenever TableMetaAttrs
is parcelling or re-building itself, it can call putParcelable
and getParcelable
for the table field.
edit:
I'm assuming Tables is a class you created, so it's signature must be
public class Tables implements Parcelable{
// and somewhere in this code tables have to parcel all it's primitives
}
then whenever TableMetaAttrs is parcelling it's values it calls:
parcel.putParcelable(table);
and rebuilding it:
table = parcel.getParcelable();
来源:https://stackoverflow.com/questions/14937009/how-to-use-parcelable-on-non-primitive-types