码迷,mamicode.com
首页 > 移动开发 > 详细

在android中创建包含对象数组的Parcelable

时间:2015-03-12 17:20:39      阅读:548      评论:0      收藏:0      [点我收藏+]

标签:android   parcelable   

public class Bill implements Parcelable{
	// 订单号
	public int orderid;
	// 原系统id
	public int oldid;
	// 订单地址
	public String address;
	// 订单备注
	public String ext;
	// 订单电话
	public String mobile;
	// 订单用户姓名
	public String name;
	// 已支付金额
	public double payed;
	// 订单时间
	public String date;
	// 订单总价
	public double total;
	// 所需付款
	public double pay;
	// 店铺名称
	public String shopname;
	// 店铺电话
	public String shopphone;
	// 订单状态,0待确定,1已确定
	public int state;
	// 接受此订单的员工
	public int staff;
	//是否送达,0未送达,1送达
	public int type;
	// 货物
	public Goods goods[];
	
	public Bill() {
		// TODO Auto-generated constructor stub
	}
	 protected Bill(Parcel in) {
	        orderid = in.readInt();
	        oldid = in.readInt();
	        address = in.readString();
	        ext = in.readString();
	        mobile = in.readString();
	        name = in.readString();
	        payed = in.readDouble();
	        date = in.readString();
	        total = in.readDouble();
	        pay = in.readDouble();
	        shopname = in.readString();
	        shopphone = in.readString();
	        state = in.readInt();
	        staff = in.readInt();
	        type = in.readInt();
	        
	        Parcelable[] parcelables = in.readParcelableArray(Goods.class.getClassLoader());
	        if (parcelables != null) {
				goods = Arrays.copyOf(parcelables, parcelables.length, Goods[].class);
			}
	    }

	    @Override
	    public int describeContents() {
	        return 0;
	    }

	    @Override
	    public void writeToParcel(Parcel dest, int flags) {
	        dest.writeInt(orderid);
	        dest.writeInt(oldid);
	        dest.writeString(address);
	        dest.writeString(ext);
	        dest.writeString(mobile);
	        dest.writeString(name);
	        dest.writeDouble(payed);
	        dest.writeString(date);
	        dest.writeDouble(total);
	        dest.writeDouble(pay);
	        dest.writeString(shopname);
	        dest.writeString(shopphone);
	        dest.writeInt(state);
	        dest.writeInt(staff);
	        dest.writeInt(type);
	        dest.writeParcelableArray(goods, flags);
	    }

	    @SuppressWarnings("unused")
	    public static final Parcelable.Creator<Bill> CREATOR = new Parcelable.Creator<Bill>() {
	        @Override
	        public Bill createFromParcel(Parcel in) {
	            return new Bill(in);
	        }

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

Goods对象实现了Parcelable接口

在android中创建包含对象数组的Parcelable

标签:android   parcelable   

原文地址:http://blog.csdn.net/qq634416025/article/details/44222301

(2)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!