小编典典
public class ImageContainer implements Serializable, Parcelable {
/**
*
*/
private static final long serialVersionUID = 1L;
public ImageContainer() {
// TODO Auto-generated constructor stub
}
public ImageContainer(Parcel in) {
// TODO Auto-generated constructor stub
readFromParcel(in);
}
/**
* custom images in this article
*/
@SerializedName("Image")
ArrayList alCustomImages=new ArrayList();
public ArrayList getAlCustomImages() {
return alCustomImages;
}
public void setAlCustomImages(ArrayList alCustomImages) {
this.alCustomImages = alCustomImages;
}
@Override
public int describeContents() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
// TODO Auto-generated method stub
dest.writeList(alCustomImages);
}
@SuppressWarnings("unchecked")
private void readFromParcel(Parcel in) {
// TODO Auto-generated method stub
this.alCustomImages = in.readArrayList(ImageCls.class.getClassLoader());
}
@SuppressWarnings("rawtypes")
public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
public ImageContainer createFromParcel(Parcel in) {
return new ImageContainer(in);
}
public ImageContainer[] newArray(int size) {
return new ImageContainer[size];
}
};
}
您的课程应该实现Parcelable。上面的代码就是一个例子。
您的问题是您正在尝试将通用数据类型读取/写入包裹。 但是无法在包裹中读取/写入通用数据类型。了解更多如何使用Parcelable
这里
和包裹在这里
2020-11-01