如何使用ArrayList <object>正确实现Parcelable?

时间:2018-04-05 11:10:39

标签: android object arraylist parcelable

我班上有一个ArrayList。我尝试将其传递给Parcelable,但收到错误。 下面是类的结构和代码本身。我怎样才能传递这类数据?

class Lists{
    String name_opt;
    byte[] value;
}

class ConfigStruct{
    String page;
    String name;
    String type;
    byte[] val_size;
    byte[] max_lenght;
    byte[] min_lenght;
    byte[] value;
    List<Lists> list;
    View view;
}

ConfigStructParcelable

public class ConfigStructParcelable implements Parcelable {

    List<Tabs.ConfigStruct> structs;

    public ConfigStructParcelable(ArrayList<Tabs.ConfigStruct> data){
        this.structs = data;
    }
    public ConfigStructParcelable(Parcel in){

        this.structs = in.readArrayList(null);//?
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeList(structs); //?
    }

    public static Creator<ConfigStructParcelable> CREATOR = new Creator<ConfigStructParcelable>() {
        @Override
        public ConfigStructParcelable createFromParcel(Parcel source) {
            return new ConfigStructParcelable(source);
        }

        @Override
        public ConfigStructParcelable[] newArray(int size) {
            return new ConfigStructParcelable[size];
        }
    };

}

我标记了两个位置&#34; //?&#34;了解如何正确写入包裹以及如何重建包裹。

发布链接没有帮助。

how to properly implement Parcelable with an ArrayList<Parcelable>?

0 个答案:

没有答案