gpt4 book ai didi

android - 扩展 Parcelable 以读取另一个 Parcelable

转载 作者:行者123 更新时间:2023-11-29 00:44:31 28 4
gpt4 key购买 nike

我有一个扩展 Parcelable 的类,我们称它为 A 类。

我有另一个扩展 Parcelable 的类,我们称之为 B 类。

A 的成员变量之一是 B 类对象的 ArrayList。

我正在尝试编写 Parcelable 覆盖,但不知道如何保存和读取 B 类的 ArrayList。

有读取和写入 ArrayLists 的方法,但他们想要一个参数,它是一个 ClassLoader,我不熟悉它。我也可以将 ArrayList 复制到一个数组中,并使用方法来读取和写入 Parcelable 数组,但这也需要一个 ClassLoader 参数。

更新:

看起来像

in.readTypedList(mList, ClassB.CREATOR);

out.writeTypedList(mList);

是我要找的吗?

最佳答案

您可以将 null 作为 ClassLoader 传递以使用默认值。

Parcel.readTypedList()Parcel.writeTypedList() 似乎没问题。或者您可以使用 Parcel.readParcelableArray()Parcel.writeParcelableArray() 并将列表转换为数组。

关于android - 扩展 Parcelable 以读取另一个 Parcelable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7196643/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com