2013-02-18 48 views
1

我有一個類TableMetaAttrs:如何在非原始類型上使用Parcelable?

public class TableMetaAttrs implements Parcelable 
{ 
    private Integer id; 
    private String name; 
    private String value; 
    private Tables table; 
... 

怎樣才能在領域實現Parcelable? 類表也實現了Parcelable。

+0

如果'Tables'實現'Parcelable',則不需要執行任何特定的序列化/反序列化table。 – Rajesh 2013-02-18 13:04:10

回答

0

您還必須製作Tablesimplements Parcelable

這種方式每當TableMetaAttrs正在parcelling或重新建設自己,它可以呼叫putParcelablegetParcelable表的字段。

編輯:

我假設表爲您創建一個類,所以它的簽名必須是

public class Tables implements Parcelable{ 
    // and somewhere in this code tables have to parcel all it's primitives 
} 

那麼只要TableMetaAttrs被瓜分它的價值它要求:

parcel.putParcelable(table); 

並重建它:

table = parcel.getParcelable(); 
+0

如果我理解你,那麼我的構造函數應該看起來像這樣? 'public TableMetaAttrs(Parcel in) \t { \t \t id = in.readInt(); \t \t name = in.readString(); \t \t value = in.readString(); \t \t table = in.readParcelable(table.getClass()。getClassLoader()); \t}' – cutoff 2013-02-18 13:08:31

+0

這是什麼?它沒有顯示在你的coment上 – Budius 2013-02-18 13:09:19

+0

table = parcel.getParcelable();將不起作用; parcel.readParcelable()可能。 – axd 2015-06-18 09:22:52