且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将自定义对象的数组列表传递给另一个活动

更新时间:2022-12-11 11:42:36

DoctorObject#writeToParcel()不能为空,这实际上是复制对象数据的内容。

You can't have DoctorObject#writeToParcel() empty, that is what actually copies the object data.

@Override
public void writeToParcel(Parcel dest, int flags) {
    // the order you write to the Parcel has to be the same order you read from the Parcel
    dest.writeInt(DocPic);
    dest.writeString(Docname);
    dest.writeString(Docspecialty);
    dest.writeString(DocLocation);
}

要在其他活动中读回数据,请使用 getParcelableArrayListExtra

And to read back your data in the other activity, use getParcelableArrayListExtra

ArrayList<DoctorObject> list = b.getParcelableArrayListExtra("NAME");