2014-03-07 91 views
1

你好,我需要從一個活動發送列表到另一個,我發現方法在包裹 readTypedList發送列表位的AMD寫TypedList 我writethem像在parcelable

 parcel.writeTypedList(busImages); 

,並嘗試像

調用
 in.readTypedList(busImages,Bitmap.Creator); 

但在第二個參數Bitmap.Creator中有錯誤,我需要創建自己的創建者還是如何解決這個問題? 類代碼:

public class ExtendBusModel extends BusModelParcelable { 
private List<Bitmap> busImages; 
private String Country; 

public ExtendBusModel(BusModelParcelable model, List<Bitmap> busImages, String country) { 
    super(model, model.getCountOfPlaces(),model.getTransportClass()); 
    this.busImages = busImages; 
    Country = country; 
} 

protected ExtendBusModel(Parcel in) { 
    super(in); 
    Log.d("read parsel buses", TestTags.TAG1); 
    // in.readList(busImages,List.class.getClassLoader()); 
    in.readTypedList(busImages,Bitmap.Creator); 
    Log.d("read parcel coutry",TestTags.TAG1); 
    Country = in.readString(); 
    Log.d("done read",TestTags.TAG1); 
    // super(in); 
} 

@Override 
public void writeToParcel(Parcel parcel, int i) { 
    super.writeToParcel(parcel, i); 
    //parcel.writeList(busImages); 
    parcel.writeTypedList(busImages); 
    parcel.writeString(Country); 
} 

public static final Creator<ExtendBusModel> CREATOR = new Creator<ExtendBusModel>() { 

    @Override 
    public ExtendBusModel createFromParcel(Parcel in) { 
     return new ExtendBusModel(in); 
    } 

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

public List<Bitmap> getBusImages() { 
    if(busImages == null) 
     return new ArrayList<Bitmap>(); 
    return busImages; 
} 

public void setBusImages(List<Bitmap> busImages) { 
    this.busImages = busImages; 
} 

public String getCountry() { 
    return Country; 
} 

public void setCountry(String country) { 
    Country = country; 
} 

}

+0

請發佈完整的課程代碼,它實現了'Parcalable'。 –

+0

@HamidShatu我貼吧 – Abbath

+0

@Clay位圖對象 – Abbath

回答

0

撰寫您CREATOR如下......這可能是解決你的問題。

public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { 
    public ExtendBusModel createFromParcel(Parcel in) { 
     return new ExtendBusModel(in); 
    } 

    public ExtendBusModel[] newArray(int size) { 
     new ExtendBusModel[size]; 
    } 
}; 
+0

parcel.writeParcelable(busImages,flags);包裹canot中出現錯誤 – Abbath

+0

@Abbath ...查看我更新的答案。 –