较为复杂的实现Parcelable的子类--推荐Android中使用
2017-08-14 21:23:34
一个较为复杂的Parcelable实现类
public class CommentShareBean implements Parcelable {
/**
* 提示文案
*/
public String shareTitle;
/**
* 商家名称
*/
public String poiName;
/**
* 商家icon
*/
public String poiIcon;
/**
* 订单评分
*/
public int commentScore;
/**
* 评论
*/
public String commentContent;
/**
* 赞商品
*/
public List<PraiseFood> praiseFoodList;
/**
* 生成二维码的url
*/
public String poiShareUrl;
/**
* slogan(icon+文案)
*/
public String mtSlogan;
/**
* 二维码分享文案
*/
public String urlTip;
/**
* 可分享 道[1,2] 1:微信朋友圈 2:微信好友 3:qq空间 4:qq好友
*/
public List<Integer> channels;
public CommentShareBean() {
}
private CommentShareBean(Parcel in) {
shareTitle = in.readString();
poiName = in.readString();
poiIcon = in.readString();
commentScore = in.readInt();
commentContent = in.readString();
if (in.readByte() == (byte) 1) {
PraiseFood[] foods = in.createTypedArray(PraiseFood.CREATOR);
praiseFoodList = Arrays.asList(foods);
}
poiShareUrl = in.readString();
mtSlogan = in.readString();
urlTip = in.readString();
if (in.readByte() == (byte) 1) {
int[] chas = in.createIntArray();
channels = new ArrayList<>();
for (int i = 0; i < chas.length; i++) {
channels.add(chas[i]);
}
}
}
@Override
public int describeContents() {
return 9887;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(shareTitle);
dest.writeString(poiName);
dest.writeString(poiIcon);
dest.writeInt(commentScore);
dest.writeString(commentContent);
if (praiseFoodList != null && praiseFoodList.size() > 0) {
dest.writeByte((byte) 1);
PraiseFood[] ps = new PraiseFood[praiseFoodList.size()];
for (int i = 0; i < praiseFoodList.size(); i++) {
ps[i] = praiseFoodList.get(i);
}
dest.writeTypedArray(ps, 0);
} else {
dest.writeByte((byte) 0);
}
dest.writeString(poiShareUrl);
dest.writeString(mtSlogan);
dest.writeString(urlTip);
if (channels != null && channels.size() > 0) {
dest.writeByte((byte) 1);
int[] chas = new int[channels.size()];
for (int i = 0; i < channels.size(); i++) {
chas[i] = channels.get(i);
}
dest.writeIntArray(chas);
} else {
dest.writeByte((byte) 0);
}
}
public static final Creator<CommentShareBean> CREATOR = new Creator<CommentShareBean>() {
@Override
public CommentShareBean createFromParcel(Parcel source) {
return new CommentShareBean(source);
}
@Override
public CommentShareBean[] newArray(int size) {
return new CommentShareBean[size];
}
};
public static class PraiseFood implements Parcelable {
public String foodName;
public PraiseFood(String name) {
foodName = name;
}
public PraiseFood(Parcel in) {
foodName = in.readString();
}
@Override
public int describeContents() {
return 12345;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(foodName);
}
public static final Parcelable.Creator<PraiseFood> CREATOR = new Parcelable.Creator<PraiseFood>() {
@Override
public PraiseFood createFromParcel(Parcel source) {
return new PraiseFood(source);
}
@Override
public PraiseFood[] newArray(int size) {
return new PraiseFood[size];
}
};
}
}
较为复杂的实现Parcelable的子类--推荐Android中使用的更多相关文章
- Android中Serializable和Parcelable序列化对象详解
学习内容: 1.序列化的目的 2.Android中序列化的两种方式 3.Parcelable与Serializable的性能比较 4.Android中如何使用Parcelable进行序列化操作 5.P ...
- 强烈推荐android studio用的几个插件
http://blog.csdn.net/liang5630/article/details/46366901 android studio常用插件,可极大简化开发,增强开发效率. 不懂安装studi ...
- 强烈推荐android studio用的几个插件,androidstudio
不懂安装studio插件,看参考博文:android stuido插件安装:http://blog.csdn.net/liang5630/article/details/46372447 1.Butt ...
- Android中Parcelable接口
1. Parcelable接口 Interface for classes whose instances can be written to and restored from a Parcel. ...
- (转)Android中Parcelable接口用法
1. Parcelable接口 Interface for classes whose instances can be written to and restored from a Parcel. ...
- Android中Parcelable和Serializable接口用法
1. Parcelable接口 Interface for classes whose instances can be written to and restored from a Parcel. ...
- Android中Parcelable与Serializable接口用法
转自: Android中Parcelable接口用法 1. Parcelable接口 Interface for classes whose instances can be written to a ...
- Android中的Parcelable接口和Serializable使用方法和差别
Parcelable接口: Interface for classes whose instances can be written to and restored from a Parcel. Cl ...
- Android中如何使用Intent在Activity之间传递对象[使用Serializable或者Parcelable]
http://blog.csdn.net/cjjky/article/details/6441104 在Android中的不同Activity之间传递对象,我们可以考虑采用Bundle.putSeri ...
随机推荐
- 20171012--jq 遍历取值
1.父节点:parent(); 2.子节点:children(); 3.兄弟节点:siblings(); 4.用find:$("div").find("span" ...
- Java 基础知识点小结
小知识点 所有的程序,都要定义在类里面: 异常 定义方法时,使用 throws 可以用来捕获方法体内没有捕获的异常,然后以 SomeException 抛出异常 java是解释型语言.java虚拟机能 ...
- GitLab本地、远程更新已经fork的项目
单用IDEA无法做到,必须配合使用Git命令行才能做到,而且是先从原作者项目更新本地库,再从本地库push到自己远程fork项目,非常坑逼. 1.到项目clone的根目录右键Git Bash,先查看远 ...
- Ubuntu 远程 Jupyter 配置
Ubuntu 远程 Jupyter 配置 每次上课都要重新部署环境,最近看到阿里云的大学生优惠活动,就着手了一台云服务器,于是就把环境部署在上面了. 环境:阿里云 Ubuntu 16.04 64位 新 ...
- 比原链(Bytom)先知节点 Windows接入文档
系统要求 我们建议选择知名的VPS服务商,运行比原链节点对算力没有要求,但是请配置尽可能大的磁盘空间. 节点服务器最小配置: 操作系统: Windows/Linux/Docker CPU: 2核 内存 ...
- Redis 单机版
Redis 支持单机版和集群,下面的步骤是单机版安装步骤 1. # yum install -y gcc-c++ 1.1 由于是c语言编写,所以需要安装支持组件 2. 把压缩包上传到linux服务器上 ...
- 找出 Xcode 编译C/C++过程文件及生成文件
在使用 Xcode 编写C/C++时,会发现在项目的目录位置是没有编译过程的那些 .o .exe 文件,只有一个 C/C++ 源代码 .c 文件.如下图(在Mac OS的finder中右键窗口标题名称 ...
- StringBuffer的delete方法与deleteCharAt方法的区别。
delete方法与deleteCharAt两个方法都是用来删除StringBuffer字符串指定索引字符的方法, delete(int begin,int end)有两个参数,使用时删除索引从be ...
- Mysql 索引之B+tree
InnoDB使用的是聚簇索引,将主键组织到一棵B+树中,而行数据就储存在叶子节点上,若使用"where id = 14"这样的条件查找主键,则按照B+树的检索算法即可查找到对应的叶 ...
- Axure下拉列表的交互事件 + 自定义元件库
下拉列表的交互事件: 场景:当点击第一个下拉列表框的江苏时,第二个列表框会显示江苏省的城市:当点击第一个下拉列表框的北京时,第二个列表框会显示北京市的区 操作:把第二个列表框设置为动态面板,设置为两种 ...