-1
入れ子クラスを作る方法を知る必要がありますParcelable
。入れ子クラスのパーセル化可能
私は、ネストされたクラスを作成すると、私はエラーを取得する(それはPARAMとして小包が必要です。)
コード:Appointment
は、パラメータなしのコンストラクタを持っていないため
public class BookingDetailsItem implements Parcelable {
private ServiceProviderItem serviceProvider;
public Appointment appointmentDetails;
private String notes;
public BookingDetailsItem(ServiceProviderItem serviceProvider)
{
this.serviceProvider = serviceProvider;
appointmentDetails = new Appointment(); // here it requires the parcel as required parameter
}
protected BookingDetailsItem(Parcel in) {
serviceProvider = in.readParcelable(ServiceProviderItem.class.getClassLoader());
appointmentDetails = in.readParcelable(Appointment.class.getClassLoader());
notes = in.readString();
}
public static final Creator<BookingDetailsItem> CREATOR = new Creator<BookingDetailsItem>() {
@Override
public BookingDetailsItem createFromParcel(Parcel in) {
return new BookingDetailsItem(in);
}
@Override
public BookingDetailsItem[] newArray(int size) {
return new BookingDetailsItem[size];
}
};
public String getNotes() {
return notes;
}
public void setNotes(String notes) {
this.notes = notes;
}
@Override
public int describeContents() {
return hashCode();
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeParcelable(serviceProvider, flags);
dest.writeParcelable(appointmentDetails, flags);
dest.writeString(notes);
}
public static class Appointment implements Parcelable {
private boolean isPickup;
private Date servicingDate; // servicing date and time. In case of pickup, it will be pick up date and time.
private String additionalRequirements;
protected Appointment(Parcel in) {
isPickup = in.readByte() != 0;
additionalRequirements = in.readString();
}
public static final Creator<Appointment> CREATOR = new Creator<Appointment>() {
@Override
public Appointment createFromParcel(Parcel in) {
return new Appointment(in);
}
@Override
public Appointment[] newArray(int size) {
return new Appointment[size];
}
};
public boolean isPickup() {
return isPickup;
}
public void setPickup(boolean pickup) {
isPickup = pickup;
}
public Date getServicingDate() {
return servicingDate;
}
public void setServicingDate(Date servicingDate) {
this.servicingDate = servicingDate;
}
public String getAdditionalRequirements() {
return additionalRequirements;
}
public void setAdditionalRequirements(String additionalRequirements) {
this.additionalRequirements = additionalRequirements;
}
@Override
public int describeContents() {
return hashCode();
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeByte((byte) (isPickup ? 1 : 0));
dest.writeString(additionalRequirements);
}
}
}
良い説明.... –