public class TradeEntity implements Parcelable{ public String id; //有关进度条的参数 ArrayList<TradeStateNodeInfo> nodes; public TradeEntity() { nodes = new ArrayList<TradeStateNodeInfo>(); } /////////////////////////实现parcel接口/////////////////////////////// @Override public int describeContents() { return 0; } @Override public void writeToParcel(Parcel out, int arg1) { out.writeString(id); out.writeList(nodes); } private TradeEntity(Parcel in) { id = in.readString(); nodes = in.readArrayList(TradeStateNodeInfo.class.getClassLoader()); } public static final Parcelable.Creator<TradeEntity> CREATOR = new Parcelable.Creator<TradeEntity>() { public TradeEntity createFromParcel(Parcel in) { return new TradeEntity(in); } public TradeEntity[] newArray(int size) { return new TradeEntity[size]; } }; }
以上问题还会出现不能传值的问题,解决如下:
将 TradeStateNodeInfo 也要实现parcel接口
import android.os.Parcel; import android.os.Parcelable; /** * 交易状态 * @author huqiang * */ public class TradeStateNodeInfo implements Parcelable{ public int active; //颜色激活(-1、错误;0、未激活;1、激活;2、当前步骤成功) public String time ; public String name ; //节点名称 public TradeStateNodeInfo() {} private TradeStateNodeInfo(Parcel in) { active = in.readInt(); time = in.readString(); name = in.readString(); } @Override public int describeContents() { return 0; } @Override public void writeToParcel(Parcel out, int flag) { out.writeInt(active); out.writeString(time); out.writeString(name); } public static final Parcelable.Creator<TradeStateNodeInfo> CREATOR = new Parcelable.Creator<TradeStateNodeInfo>() { public TradeStateNodeInfo createFromParcel(Parcel in) { return new TradeStateNodeInfo(in); } public TradeStateNodeInfo[] newArray(int size) { return new TradeStateNodeInfo[size]; } }; }