0

我想知道我的课程是否有问题,因为我无法将额外的(由 Note 对象组成)从一个活动传递给另一个

这是我的 Parcelable 类的代码: 注意:

public class Note implements Parcelable {

    public static int compteur = 0;
    long id;
    String summary;
    String details;

    public Note(String summary, String details) {
        super();
        compteur = compteur + 1;
        this.id = compteur;
        this.summary = summary;
        this.details = details;
    }

    public Note() {
        super();
    }

    ///// getters and settters /////

    @Override
    public String toString() {
        return "Note " + id + " (" + summary + ") --> Details: " + details;
    }

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

    @Override
    public void writeToParcel(Parcel dest, int arg1) {
        // TODO Auto-generated method stub
        dest.writeLong(id);
        dest.writeString(summary);
        dest.writeString(details);

    }

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

        @Override
        public Note createFromParcel(Parcel in) {
            // TODO Auto-generated method stub
            return new Note(in);
        }

        public Note[] newArray(int size) {
            return new Note[size];
        }
    };

    private Note(Parcel in) {
        this.id = in.readInt();
        this.summary = in.readString();
        this.details = in.readString();
    }
}

或者问题可能出在其他任何地方?

4

1 回答 1

0

尝试使您的 Note 构造函数接受 Parcel 公开。

  public Note(Parcel in) {
        this.id = in.readInt();
        this.summary = in.readString();
        this.details = in.readString();
    }
于 2013-04-21T19:50:44.533 回答