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