首页 > 代码库 > android实现Parcelable序列化对象
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); } }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。