android中实现Parcelable序列化步骤
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序列化步骤的更多相关文章
- Android中的Parcelable接口和Serializable使用方法和差别
Parcelable接口: Interface for classes whose instances can be written to and restored from a Parcel. Cl ...
- Android中使用Parcelable
今天 在两个Activity之间传集合类型数据,看了一下,要用Parcelable 所以就看一下东西: 下面一段话是复制网友的. Android序列化对象主要有两种方法,实现Serializable接 ...
- Android中SharedPreferences和序列化结合保存对象数据
前言: 最近在做用户注册的时候,遇到了需要填写很多表单数据,不可能在一页把所有的数据都展示完全,因此采用了分页的方式,由于在用户填写数据数据之后我们需要对用户填写的数据进行暂时的记录的,当用户会到此页 ...
- Android中ListView的使用步骤
第一步: 首先,在 布局文件中,声明listView控件. <ListView android:id="@+id/lv" android:layout_width=&quo ...
- 在android中进行单元测试的步骤
若不知道怎么配上面两个参数
- Android中Parcelable序列化总结
在使用Parcelable对android中数据的序列化操作还是比较有用的,有人做过通过对比Serializable和Parcelable在android中序列化操作对象的速度比对,大概Parcela ...
- Android中Serializable和Parcelable序列化对象详解
学习内容: 1.序列化的目的 2.Android中序列化的两种方式 3.Parcelable与Serializable的性能比较 4.Android中如何使用Parcelable进行序列化操作 5.P ...
- Android中Parcelable接口
1. Parcelable接口 Interface for classes whose instances can be written to and restored from a Parcel. ...
- 浅谈Android中Serializable和Parcelable使用区别
版权声明:本文出自汪磊的博客,转载请务必注明出处. 一.概述 Android开发的时候,我们时长遇到传递对象的需求,但是我们无法将对象的引用传给Activity或者Fragment,我们需要将这些对象 ...
随机推荐
- 学习Slim Framework for PHP v3 (五)--route怎么被调用的?
上一篇中分析了get()如何加入新的route的,这篇来分析route是如何被调用的. 首先,route是在routers里保存,router有在container中存放.container提供了ge ...
- C++ 单链表的基本算法
线性表是最简单,最常用的一种数据结构.线性表的逻辑结构是n个数据元素的有限序列(a1,a2,…,an).而线性表的物理结构,我们已经学习过顺序表,也就是数组 :另一种线性表的物理结构——链表 . 什么 ...
- CSS导航指示箭头
效果图 代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www. ...
- Part 3 ViewData and ViewBag in mvc
ViewBag and ViewData is a mechanism(机制) to pass data from controller to view. We use '@' symbol(符号) ...
- Oracle数据库对象_视图
视图是一种非常重要的数据库对象,它的形式类似于普通表,我们可以从视图中查询数据. 实际上它是建立在表上的一种虚表,在视图中并不存储真正的数据,而是仅仅保存一条SELECT语句,对视图的访问将被转化为对 ...
- php验证字符串是否以逗号隔开包括中文字符串
if(preg_match('/^[\x{4e00}-\x{9fa5}\w]+(,[\x{4e00}-\x{9fa5}\w]+)*$/u','体育,娱乐')){ echo 'ok';}
- Git tricks: Unstaging files
NOTE: Following content is directly reprinted from http://andrewberls.com/blog/post/git-tricks-unsta ...
- android-support-xxxx.jar NoClassDefFoundError
当你的项目出现以下红色提示的时候,要小心了,因为很可能因为这个错误而导致解释不通的异常出现. Found 2 versions of android-support-v4.jar in the dep ...
- Linux常用命令操作说明(链接)
1. Busybox下tftp命令使用详解 2. Linux中rc的含义 3. <Unix文件系统结构标准>(Filesystem Hierarchy Standard) 4. 用size ...
- jsp探针
在网上找到一些jsp探针,收藏下. JSP探针1.jsp <%@ page contentType="text/html;charset=gb2312" %> < ...