Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何为列表实现parcelable<;长期>;_Android - Fatal编程技术网

Android 如何为列表实现parcelable<;长期>;

Android 如何为列表实现parcelable<;长期>;,android,Android,我正在尝试传递我的包裹中的列表,执行以下操作: public class MetaDados implements Parcelable { private List<Long> sizeImages; public MetaDados(List<Long> sizeImages){ this.sizeImages = sizeImages; } public List<Long> getSizeImages() { return siz

我正在尝试传递我的包裹中的列表,执行以下操作:

public class MetaDados implements Parcelable {

private List<Long> sizeImages;

public MetaDados(List<Long> sizeImages){
this.sizeImages = sizeImages;
}

public List<Long> getSizeImages() {
        return sizeImages;
    }

    public void setSizeImages(List<Long> sizeImages) {
        this.sizeImages = sizeImages;
    }

@Override
    public int describeContents() {
        // TODO Auto-generated method stub
        return 0;
    }

@Override
    public void writeToParcel(Parcel dest, int flags) {
dest.writeList(sizeImages);
}

    public static final Parcelable.Creator<MetaDados> CREATOR = new Parcelable.Creator<MetaDados>() {
        @Override
        public MetaDados createFromParcel(Parcel in) {
            return new MetaDados(in);
        }

        @Override
        public MetaDados[] newArray(int size) {
            return new MetaDados[size];
        }
    };

private MetaDados(Parcel in) {
//HERE IS THE PROBLEM, I'VE tried this:

sizeImages = in.readList(sizeImages, Long.class.getClassLoader());

//but what i got: Type mismatch: cannot convert from void to List<Long>
}
}
公共类MetaDados实现了可包裹{
私人名单;
公共元数据(列表大小图像){
this.sizeImages=sizeImages;
}
公共列表getSizeImages(){
返回图像;
}
公共无效设置大小图像(列表大小图像){
this.sizeImages=sizeImages;
}
@凌驾
公共int描述内容(){
//TODO自动生成的方法存根
返回0;
}
@凌驾
公共无效写入包裹(包裹目的地,内部标志){
目的写入列表(SizeImage);
}
public static final Parcelable.Creator=新建Parcelable.Creator(){
@凌驾
公共MetaDados createFromParcel(地块中){
返回新的MetaDados(在中);
}
@凌驾
公共MetaDados[]新数组(整数大小){
返回新的MetaDados[大小];
}
};
私人MetaDados(地块内){
//问题出在这里,我已经试过了:
sizeImages=in.readList(sizeImages,Long.class.getClassLoader());
//但我得到的是:类型不匹配:无法从void转换为List
}
}
试试这个:

sizeImages = new ArrayList<Long>(); // or any other type of List
in.readList(sizeImages, null);
sizeImages=newarraylist();//或任何其他类型的列表
in.readList(sizeImages,null);
报告说:

从地块读入现有列表对象

因此,您需要首先创建
列表