import java.io.Serializable;
import java.text.DecimalFormat; import android.os.Parcel;
import android.os.Parcelable; /**
* 代金券/团购实体类
* @author huqiang
*
*/
public class CouponEntity implements Parcelable{
/**
* shop_id
*/
public String shop_id ;
/**
* 店铺名称
*/
public String shop_name ;
/**
* 代金券id
*/
public String coupon_id ;
/**
* 代金券编号
*/
public String coupon_no ;
/**
* 优惠券标题
*/
public String coupon_name ;
/**
* 优惠券类型 1:代金券 2:团购券
*/
public int coupon_type ; public double getCoupon_sale_amount() {
return coupon_sale_amount;
}
public void setCoupon_sale_amount(double coupon_sale_amount) {
DecimalFormat df = new DecimalFormat("#.00");
this.coupon_sale_amount = Double.parseDouble(df.format(coupon_sale_amount));
}
/**
* 允许2位小数
* @return
*/
public double getCoupon_vaules_amount() {
return coupon_vaules_amount;
}
public void setCoupon_vaules_amount(double coupon_vaules_amount) {
DecimalFormat df = new DecimalFormat("#.00");
this.coupon_vaules_amount = Double.parseDouble(df.format(coupon_vaules_amount));
}
/*---------------------实现Parcelable序列化---------------------------------*/
public CouponEntity(Parcel in)
{
shop_id = in.readString();
shop_name = in.readString();
coupon_id = in.readString();
coupon_no = in.readString();
coupon_type = in.readInt();
}
public static final Parcelable.Creator<CouponEntity> CREATOR = new Parcelable.Creator<CouponEntity>() {
public CouponEntity createFromParcel(Parcel in) {
return new CouponEntity(in);
} public CouponEntity[] newArray(int size) {
return new CouponEntity[size];
}
}; @Override
public int describeContents() {
// 内容描述,返回0即可
return 0;
}
@Override
public void writeToParcel(Parcel out, int arg1) {
out.writeString(shop_id);
out.writeString(shop_name);
out.writeString(coupon_id);
out.writeString(coupon_no);
out.writeInt(coupon_type);
} }

实现Parcelable序列化步骤
1、implements implements Parcelable
2、

    /*---------------------实现Parcelable序列化---------------------------------*/
public CouponEntity(Parcel in)
{
shop_id = in.readString();
shop_name = in.readString();
coupon_id = in.readString();
coupon_no = in.readString();
coupon_type = in.readInt();
}
public static final Parcelable.Creator<CouponEntity> CREATOR = new Parcelable.Creator<CouponEntity>() {
public CouponEntity createFromParcel(Parcel in) {
return new CouponEntity(in);
} public CouponEntity[] newArray(int size) {
return new CouponEntity[size];
}
}; @Override
public int describeContents() {
// 内容描述,返回0即可
return 0;
}
@Override
public void writeToParcel(Parcel out, int arg1) {
out.writeString(shop_id);
out.writeString(shop_name);
out.writeString(coupon_id);
out.writeString(coupon_no);
out.writeInt(coupon_type);
}

android中实现Parcelable序列化步骤的更多相关文章

  1. Android中的Parcelable接口和Serializable使用方法和差别

    Parcelable接口: Interface for classes whose instances can be written to and restored from a Parcel. Cl ...

  2. Android中使用Parcelable

    今天 在两个Activity之间传集合类型数据,看了一下,要用Parcelable 所以就看一下东西: 下面一段话是复制网友的. Android序列化对象主要有两种方法,实现Serializable接 ...

  3. Android中SharedPreferences和序列化结合保存对象数据

    前言: 最近在做用户注册的时候,遇到了需要填写很多表单数据,不可能在一页把所有的数据都展示完全,因此采用了分页的方式,由于在用户填写数据数据之后我们需要对用户填写的数据进行暂时的记录的,当用户会到此页 ...

  4. Android中ListView的使用步骤

    第一步:  首先,在 布局文件中,声明listView控件. <ListView android:id="@+id/lv" android:layout_width=&quo ...

  5. 在android中进行单元测试的步骤

    若不知道怎么配上面两个参数 

  6. Android中Parcelable序列化总结

    在使用Parcelable对android中数据的序列化操作还是比较有用的,有人做过通过对比Serializable和Parcelable在android中序列化操作对象的速度比对,大概Parcela ...

  7. Android中Serializable和Parcelable序列化对象详解

    学习内容: 1.序列化的目的 2.Android中序列化的两种方式 3.Parcelable与Serializable的性能比较 4.Android中如何使用Parcelable进行序列化操作 5.P ...

  8. Android中Parcelable接口

    1. Parcelable接口 Interface for classes whose instances can be written to and restored from a Parcel. ...

  9. 浅谈Android中Serializable和Parcelable使用区别

    版权声明:本文出自汪磊的博客,转载请务必注明出处. 一.概述 Android开发的时候,我们时长遇到传递对象的需求,但是我们无法将对象的引用传给Activity或者Fragment,我们需要将这些对象 ...

随机推荐

  1. JavaScript--正则表达式(笔记)

    一 什么是正则表达式 // 正则表达式(regular expression)是一个描述字符模式的对象; // JS定义RegExp类表示正则表达式; // String和RegExp都定义了使用正则 ...

  2. HTML页面背景音乐控制

    //兼容ie,chrome,safari. <object id="AudioID" type="application/x-mplayer2" data ...

  3. postfix部署多个Content Filter的方法

    Postfix邮件服务器可以在接收邮件时使用content_filter来扫描邮件(病毒,广告等).通过整合一个集中化的电子邮件内容过滤器,比如amavis或mailscanner,Postfix可以 ...

  4. js 获取url 参数

    $(function () { var WeixinCode = GetQueryString("WeixinCode"); $("#ProXQ").attr( ...

  5. 第七篇、OC_图片的裁剪基于SDWebImage

    前期有段时间困扰了我很久一个问题由于工程中的图片数据抓取自不同平台,所以图片的大小尺寸不一定,而放置图片的imageView尺寸是一定的,不作任何处理的话会导致图片拉伸变形,因此找了好久解决办法,现把 ...

  6. 第一个Cocos2d-x Lua游戏

    我们的编写的第一个Cocos2d-x Lua程序,命名为HelloLua,从该工程开始学习其它的内容.创建工程我们创建Cocos2d-x Lua工程可以通过Cocos2d-x提供的命令工具cocos实 ...

  7. 转载:python文件打开方式详解——a、a+、r+、w+区别

    第一步 排除文件打开方式错误: r只读,r+读写,不创建      ###f.readline()是读取第一行,f.readlines()是读取全部并返回一个列表 w新建只写,w+新建读写,会将文件内 ...

  8. windows通过thrift访问hdfs

    thirift是一个支持跨种语言的远程调用框架,通过thrift远程调用框架,结合hadoop1.x中的thriftfs,编写了一个针对hadoop2.x的thriftfs,供外部程序调用. 1.准备 ...

  9. ●linux进程的查看与操作●

    查看进程:ps -le | more ,ps -aux | more ,ps & 后台运行  jobs 查看后台进程  fg [n]调到前台  bg放到后台 ctrl +c 终止  ctrl ...

  10. Andriod docs加载速度慢的问题解决

    网上找了个类, import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import ja ...