标签:
//实体bean
package org.mo.common.util.entity; import java.util.Date; import android.os.Parcel; import android.os.Parcelable; /** * * @author moziqi * */ public class BeanDemo implements Parcelable { private Integer id; private String name; private Date createTime; public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Date getCreateTime() { return createTime; } public void setCreateTime(Date createTime) { this.createTime = createTime; } @Override public String toString() { return "BeanDemo [id=" + id + ", name=" + name + ", createTime=" + createTime + "]"; } @Override public int describeContents() { return 0; } @Override public void writeToParcel(Parcel dest, int flags) { // 序列化 dest.writeInt(id); dest.writeString(name); dest.writeSerializable(createTime); } public static final Parcelable.Creator<BeanDemo> CREATOR = new Creator<BeanDemo>() { @Override public BeanDemo[] newArray(int size) { return new BeanDemo[size]; } @Override public BeanDemo createFromParcel(Parcel source) { // 网上说一定要按顺序来写 // 必须按成员变量声明的顺序读取数据,不然会出现获取数据出错 // 反序列化 BeanDemo beanDemo = new BeanDemo(); beanDemo.setId(source.readInt()); beanDemo.setName(source.readString()); // 查看Date的父类是Serializable beanDemo.setCreateTime((Date) source.readSerializable()); return beanDemo; } }; }
//对应的一个table类
package org.mo.common.util.table; public class BaseTABLE { public final static String ID = "_id"; }
//
package org.mo.common.util.table; public class BeanDemoTABLE extends BaseTABLE { public final static String NAME = "name"; public final static String CREATE_TIME = "create_time"; }
(android-001)非基本类型实现Parcelable使用
标签:
原文地址:http://my.oschina.net/moziqi/blog/364850