Android Parcelable - read/write data to Parcel using generic data type(Android Parcelable - 使用通用数据类型读取/写入数据到 Parcel)
问题描述
How can i implement to write my Set < ArrayList < ? > >
to my Parcel using generic data type ?
Here is my code..
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];
}
};
}
your class should implement Parcelable. An example is in above code.
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
这篇关于Android Parcelable - 使用通用数据类型读取/写入数据到 Parcel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Android Parcelable - 使用通用数据类型读取/写入数据到 Parcel
基础教程推荐
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 降序排序:Java Map 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01