gpt4 book ai didi

java - Android Parcelable - 使用通用数据类型将数据读/写到 Parcel

转载 作者:行者123 更新时间:2023-12-02 04:54:59 30 4
gpt4 key购买 nike

我如何实现写我的Set < ArrayList < ? > >使用通用数据类型到我的包裹?

这是我的代码..

        dest.writeList(getArrTRA());
dest.writeList(getArrTSAC());
dest.write???(getArrListSet()); //how can i write my Set<ArrayList<?


public Set<ArrayList<?>> getArrListSet() {
return arrSetOfPaymentMode;
}

最佳答案

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<ImageCls> alCustomImages=new ArrayList<ImageCls>();

public ArrayList<ImageCls> getAlCustomImages() {
return alCustomImages;
}
public void setAlCustomImages(ArrayList<ImageCls> 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。上面的代码就是一个例子。

Your issue is you are trying to read/write generic data type to the Parcel. But it is not possible to read/write generic data type in parcel. Read more how to use Parcelable here and Parcel here

关于java - Android Parcelable - 使用通用数据类型将数据读/写到 Parcel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28869067/

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