首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何封装short[]数组?

如何封装short[]数组?
EN

Stack Overflow用户
提问于 2015-07-17 10:35:37
回答 1查看 778关注 0票数 0

如何封装下列参数?

代码语言:javascript
复制
short[] types;

从现在起我试过这个:

代码语言:javascript
复制
// Write to parcel
dest.writeValue(types);

// Read from parcel
???

我怎样才能做到这一点?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-07-17 10:56:21

对于短数组,不能直接从包中读写。http://developer.android.com/reference/android/os/Parcel.html

你可以这样做。

代码语言:javascript
复制
// write
dest.writeInt(types.length);
for (int i = 0; i < types.length; i++) {
    dest.writeInt((int) types[i]);
}

// read
len = parcel.readInt();
short[] types = new short[len];
for (int i = 0; i < len; i++) {
    types[i] = (short) parcel.readInt();
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31473882

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档