较为复杂的实现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 ...
随机推荐
- Windows环境下利用anaconda3安装python版本的Xgboost
网上有各种不同安装Xgboost的教程,但是有些教程对于一个新手来说,照着做安装成功是很困难的.本人也是新手,第一次安装Xgboost的时候,照着某个教程做,结果总是安装不上,甚至想到要放弃.后来经一 ...
- eclipse改jsp文件编码格式 统一设置
- 使用RStudio调试(debug)基础学习(二)和fGarch包中的garchFit函数估计GARCH模型的原理和源码
一.garchFit函数的参数--------------------------------------------- algorithm a string parameter that deter ...
- How Many Zeroes? LightOJ - 1140
#include<stdio.h> #include<string.h> #include<math.h> #include<time.h> #incl ...
- nc(NetCat)命令
瑞士军刀netcat官网:http://netcat.sourceforge.net/ 安装:yum install -y nc查询:rpm -q nc 语法:nc [-hlnruz][-g<网 ...
- fiddler抓不到chrome浏览器的请求
今天遇到一个非常尴尬的问题,接口在某种情况下会报错,此时前端会展示NAN之类的东西,由于复现不了,接口现在一直不报 错了,所以就让前端做了个友好提示, 当接口报错时,给个提示“请稍后重试” ,我要测试 ...
- Oracle解决ora-01653 无法通过1024扩展
综合上述检查结果,可断定遇到的问题是因为可能性1—表空间不足导致.解决办法也就是扩大表空间 扩大表空间的四种方法: 1.增加数据文件 ALTER TABLESPACE ***_TRD ADD DATA ...
- js vue 在页面中将摄像头放在一个标签里展示,(模仿手机拍照功能)
1.HTML <video id="video" autoplay class="fileImg"></video> <canva ...
- 初步接触gulp
首先是安装nodejs,通过nodejs的npm全局安装和项目安装gulp,其次在项目里安装所需要的gulp插件,然后新建gulp的配置文件gulpfile.js并写好配置信息(定义gulp任务),最 ...
- UnicodeEncodeError: 'gbk' codec can't encode character '\xbb' in position 30633: illegal multibyte sequence
import urllib.request def load_baidu(): url = "https://www.baidu.com/" header = {"Use ...