gpt4 book ai didi

java - 如何对具有 List 的对象进行 Parcelable

转载 作者:行者123 更新时间:2023-12-02 02:48:15 25 4
gpt4 key购买 nike

我有一个类 Episode,其中包含 Person 对象的数组列表。当我解析 Episode 对象时,我可以成功获取数据,但不能获取列表。

实现 Parseable 的剧集类代码:

protected Episode(Parcel in) {
id = in.readInt();
number = in.readInt();
seasonNumber = in.readInt();
rating = in.readDouble();
name = in.readString();
overview = in.readString();
date = in.readString();
image = in.readString();
crew = in.createTypedArrayList(Person.CREATOR);
guestStars = in.createTypedArrayList(Person.CREATOR);
}

public static final Creator<Episode> CREATOR = new Creator<Episode>() {
@Override
public Episode createFromParcel(Parcel in) {
return new Episode(in);
}

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

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

@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(id);
dest.writeInt(number);
dest.writeInt(seasonNumber);
dest.writeDouble(rating);
dest.writeString(name);
dest.writeString(overview);
dest.writeString(date);
dest.writeString(image);
dest.writeTypedList(crew);
dest.writeTypedList(guestStars);
}

Person 类也实现了 Parseable:

protected Person(Parcel in) {
id = in.readInt();
name = in.readString();
creditId = in.readString();
gender = in.readString();
profile = in.readString();
character = in.readString();
department = in.readString();
job = in.readString();
}

public static final Creator<Person> CREATOR = new Creator<Person>() {
@Override
public Person createFromParcel(Parcel in) {
return new Person(in);
}

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

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

@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(id);
dest.writeString(name);
dest.writeString(creditId);
dest.writeString(gender);
dest.writeString(profile);
dest.writeString(character);
dest.writeString(department);
dest.writeString(job);
}

我哪里出错了,无法获取Person列表?

谢谢

最佳答案

以上是正确的。我只是犯了一个简单的错误,没有正确显示数据。

关于java - 如何对具有 List<Custom Object> 的对象进行 Parcelable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57128791/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com