最佳答案
我在下面创建了一个 Parcelable
对象,我的对象包含产品的 List
。在构造函数中,如何为 List
重新创建 Parcelable
?
我已经检查了所有的方法可从包裹和所有可用的是 readArrayList(ClassLoader)
。我不确定这是不是最好的方法,我真的很感激你的建议。
public class Outfits implements Parcelable {
private String url;
private String name;
private List<Product> products;
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<Product> getProducts() {
return products;
}
public void setProducts(List<Product> products) {
this.products = products;
}
public void writeToParcel(Parcel dest, int flags) {
Log.v("", "writeToParcel..." + flags);
dest.writeString(url);
dest.writeString(name);
dest.writeList(products);
}
public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
public Outfits createFromParcel(Parcel in) {
return new Outfits(in);
}
public Outfits[] newArray(int size) {
return new Outfits[size];
}
};
@Override
public int describeContents() {
return 0;
}
/*** Here how do I populate my List of Products ***/
private Outfits(Parcel in) {
url = in.readString();
name = in.readString();
products = in.read ???????;
}
}