android实现Parcelable序列化对象
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); } }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。