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. Bootstrap 小技巧以及相关资源整理

    1, Bootstrap Bundle (http://bootstrapbundle.com/): 提供了15中不同的MVC  Bootstrap模板.[扩展和更新]中搜索“Bootstrap Bu ...

  2. Backbone.js学习之View

    千呼万唤始出来,终于到最后一个要点View了.照旧,先来一睹官方文档: Backbone views are almost more convention than they are code - t ...

  3. OC Categroy类别

    Categroy类别,又称为扩展类,在类的原基础上扩展方法,且不可添加变量,如果扩展的方法与原始类中的方法相同,则会隐藏原始方法,且不可在扩展方法中通过super调用原始方法,这里与继承不同. 定义: ...

  4. HTML之正则表达式

    匹配国内电话号码:d{3}-d{8}|d{4}-d{7} 评注:匹配形式如 0511-4405222 或 021-87888822 匹配腾讯QQ号:[1-9][0-9]{4,} 评注:腾讯QQ号从10 ...

  5. ORACLE 对用户密码做限制

    1. 查看默认设置 2. PASSWORD_LIFE_TIME 60 --口令的生命周期,超过这段时间口令可能会自动过期,是否过期要看是否设定了PASSWORD_GRACE_TIME PASSWORD ...

  6. Linux下动态共享库加载及使用详解【转】

    原文地址:http://blog.chinaunix.net/uid-29025972-id-3855500.html 对动态库的实际应用还不太熟悉的读者可能曾经遇到过类似“error while l ...

  7. FKP,一套全栈框架,基于react、webpack、koa1、babel

    FKP-REST是一套前后端分离,基于javascript的全栈实现,基于node的高性能,易部署性及javascript前后端语言的一致性,学习成本,时间成本及项目快速启动等等方面,FKP都是一种不 ...

  8. 微信公众号与HTML 5混合模式揭秘2——分享手机相册中照片

    本书是分享微信jssdk开发的第二篇.     4.2.1 项目需求 需求说明:实现微信端的手机用户,点击按钮选取1张图片,分享到朋友圈. 4.2.2 需求分解 通过对需求的了解,可以将其分解为: ( ...

  9. 13款精彩实用的最新jQuery插件

    1.jQuery特色菜单 圆形动画菜单插件 jQuery是一个非常流行的WEB前端框架,尽管HTML5非常酷,但是如果HTML5结合jQuery的话就能实现更酷更实用的插件.今天分享的这款jQuery ...

  10. c/c++面试总结(3)

    7.vector和list的区别(这个也算是经常问的) vector和数组类似,拥有一段连续的内存空间,并且起始地址不变,这样对随机的读取很有效率(就是我们所有的[]运算符了),因为内存是连续的如果我 ...