自定义对象的扩展(自定义)arraylist parcelable返回大小0

mwg9r5ms  于 2021-07-12  发布在  Java
关注(0)|答案(0)|浏览(282)

这是一天的工作,没有解决方案,我会传递数据beetween活动,我实现parcelable,但从调用的活动,我收到了listfilemedia与大小=0。
当我犯错的时候?

类listfilemedia(arraylist的扩展)

public class ListFileMedia extends ArrayList<FileMedia> implements Parcelable{

public ListFileMedia(){.....}

//对于测试,我取消了所有的方法和变量,当然我也测试了。。。

//Interface Parcelable

@Override
public int describeContents() {
    return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
    //dest.writeInt(countIntestazioni);
    // Add inner class
    dest.writeParcelable(this.add(FileMedia),flags);
}

public ListFileMedia(Parcel in) {

}

public final static Parcelable.Creator <ListFileMedia>CREATOR = new Creator<ListFileMedia>() {

    @Override
    public ListFileMedia createFromParcel(Parcel source) {

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

        return new ListFileMedia[size];
    }
};
}

filelistmedia中的自定义对象

public class FileMedia implements Comparable,Parcelable{

public String getPath() {return path;}

public String getBucket() {
    return bucket;
}

public String getMimeType() { return mimeType; }

private String path;
private String bucket;
private String mimeType;
private int giorno;
private int mese;
private int anno;

public FileMedia(int giorno,int mese,int anno, String path,String bucket,String mimeType){
....
}

public int compareTo(Object o) {
.....
}

  //Interface Parcelable

@Override
public int describeContents() {
    return 0;
}

@Override
public void writeToParcel(Parcel dest, int flags) {
    dest.writeString(this.path);
    dest.writeString(this.bucket);
    dest.writeString(this.mimeType);
    dest.writeInt(this.giorno);
    dest.writeInt(this.mese);
    dest.writeInt(this.anno);
}
public FileMedia(Parcel in) {
    this.path = in.readString();
    this.bucket=in.readString();
    this.mimeType=in.readString();
    this.giorno=in.readInt();
    this.mese=in.readInt();
    this.anno=in.readInt();
}
public final static Parcelable.Creator <FileMedia>CREATOR = new Creator<FileMedia>() {

    @Override
    public FileMedia createFromParcel(Parcel source) {
        return new FileMedia(source);
    }

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

呼叫活动

ListFileMedia test=new ListFileMedia();
        ArrayList arrayList=new ArrayList();
        test.add(new FileMedia(10,12,2016,"t","t","t"));
        b.putParcelable("list",test);
        intent.putExtras(b);
        startActivity(intent);

被叫活动

Intent intent = this.getIntent();
       Bundle b=intent.getExtras();

ListFileMedia listFileMedia (ListFileMedia)b.getParcelable("list"); //size==0  !!!

但如果我只通过了 b.putParcelable("list",new FileMedia(10,12,2016,"t","t","t") 正确地工作!!
对不起,我的英语。。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题