如何读/写的布尔实施Parcelable接口是什么时候?布尔、接口、时候、Parcelable

2023-09-13 02:23:26 作者:据说接吻可以长高喔

我试图做一个ArrayList Parcelable为了通过一个活动的自定义列表object.I开始写它扩展ArrayList的一个myObjectList类并实现Parcelable。

I'm trying to make an ArrayList Parcelable in order to pass to an activity a list of custom object.I start writing a myObjectList class which extends ArrayList and implement Parcelable.

MyObject来的一些属性是布尔值,但包裹没有任何方法读/ writeBoolean。

Some attributes of MyObject are boolean but Parcel don't have any method read/writeBoolean.

什么是处理这一问题的最佳方法是什么?

What is the best way to handle this?

推荐答案

下面是我会怎么办呢?

writeToParcel:

writeToParcel:

dest.writeByte((byte) (myBoolean ? 1 : 0));     //if myBoolean == true, byte == 1

readFromParcel:

readFromParcel:

myBoolean = in.readByte() != 0;     //myBoolean == true if byte != 0