我在Parcelable
下面创建了一个对象,我的对象包含一个List
产品。在我的构造函数中,如何处理Parcelable
for的重新创建List
?
我已经检查了包裹中所有可用的方法,所有可用的方法是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 ???????;
}
}
包裹类型的方法readList(List,ClassLoader)不适用于参数()
—
Byron
论证没有错。这就是经常使用列表的方式。我添加了答案。
—
Alex Gitelman
readList()
?