public class Category implements Parcelable {
private int mCategoryId;
private List<Video> mCategoryVideos;
public int getCategoryId() {
return mCategoryId;
}
public void setCategoryId(int mCategoryId) {
this.mCategoryId = mCategoryId;
}
public List<Video> getCategoryVideos() {
return mCategoryVideos;
}
public void setCategoryVideos(List<Video> videoList) {
mCategoryVideos = videoList;
}
@Override
public void writeToParcel(Parcel parcel, int i) {
parcel.writeInt(mCategoryId);
parcel.writeTypedList(mCategoryVideos);
}
public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
public Category createFromParcel(Parcel parcel) {
final Category category = new Category();
category.setCategoryId(parcel.readInt());
category.setCategoryVideos(parcel.readTypedList()); */// **WHAT SHOULD I WRITE HERE***
return category;
}
public Category[] newArray(int size) {
return new Category[size];
}
};
}
我的代码我正在使用从 Parcelable 实现的模型...任何人都可以告诉他们我在这一行中写了什么category.setCategoryVideos(parcel.readTypedList())
我找不到任何有用的帖子。
EDIT: category.setCategoryVideos(parcel.readTypedList(mCategoryVideos,Video.CREATOR));
在这里 mCategoryVideos 我无法解决错误。
Parcelable 类有一些列表方法,你可以在这里查看它们:
readList(列表outVal,ClassLoader加载器) http://developer.android.com/reference/android/os/Parcel.html#readList%28java.util.List,%20java.lang.ClassLoader%29
writeList(列表值) http://developer.android.com/reference/android/os/Parcel.html#writeList%28java.util.List%29
在你的情况下,它看起来像:
List<Object> myList = new ArrayList<>();
parcel.readList(myList,List.class.getClassLoader());
category.setCategoryVideos(myList);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)