Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> 在android中創建包含對象數組的Parcelable

在android中創建包含對象數組的Parcelable

編輯:關於Android編程

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 CREATOR = new Parcelable.Creator() {
	        @Override
	        public Bill createFromParcel(Parcel in) {
	            return new Bill(in);
	        }

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

Goods對象實現了Parcelable接口

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved