android實現Parcelable序列化對象

來源:互聯網
上載者:User

標籤:android   des   java   os   資料   re   

package com.sl.pocketbook.bean;import android.os.Parcel;import android.os.Parcelable;import android.os.Parcelable.Creator;/** * 品牌 *  * @author sxn *  */public class ProductBrandBean implements Parcelable {    /**     * id     */    private int id;    /**     * 數量     */    private int conunt;    /**     * icon     */    private String urlIcon;    /**     * 名稱     */    private String brandName;    public static final Parcelable.Creator<ProductBrandBean> CREATOR = new Creator<ProductBrandBean>() {        @Override        public ProductBrandBean createFromParcel(Parcel source) {            // TODO Auto-generated method stub            // 必須按成員變數聲明的順序讀取資料,不然會出現擷取資料出錯            ProductBrandBean p = new ProductBrandBean();            p.setId(source.readInt());            p.setConunt(source.readInt());            p.setUrlIcon(source.readString());            p.setBrandName(source.readString());            return p;        }        @Override        public ProductBrandBean[] newArray(int size) {            // TODO Auto-generated method stub            return new ProductBrandBean[size];        }    };    public String getBrandName() {        return brandName;    }    public void setBrandName(String brandName) {        this.brandName = brandName;    }    public ProductBrandBean() {    }    public int getId() {        return id;    }    public void setId(int id) {        this.id = id;    }    public int getConunt() {        return conunt;    }    public void setConunt(int conunt) {        this.conunt = conunt;    }    public String getUrlIcon() {        return urlIcon;    }    public void setUrlIcon(String urlIcon) {        this.urlIcon = urlIcon;    }    @Override    public int describeContents() {        // TODO Auto-generated method stub        return 0;    }    @Override    public void writeToParcel(Parcel dest, int flags) {        // 1.必須按成員變數聲明的順序封裝資料,不然會出現擷取資料出錯        // 2.序列化對象        dest.writeInt(id);        dest.writeInt(conunt);        dest.writeString(urlIcon);        dest.writeString(brandName);    }}




聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.