[英]Save a custom ListView's instance state?
I have a custom ListView
that uses a custom ArrayAdapter
(which basically just overrides getView()
). 我有一个自定义ListView
使用自定义ArrayAdapter
(基本上只是覆盖getView()
)。 This custom adapter uses as its backend a List<CustomObject>
. 此自定义适配器使用List<CustomObject>
作为其后端。 The elements in this List
are retrieved from the network, so I would like to save it in onSaveInstanceState()
. 此List
中的元素是从网络中检索的,因此我想将其保存在onSaveInstanceState()
。 However, I can't find a way to put a List<E>
in a Bundle
. 但是,我找不到将List<E>
放入Bundle
。 I'm thinking this is a common task, saving a custom array in the instance state. 我认为这是一个常见任务,在实例状态中保存自定义数组。 How do other people do it? 其他人怎么做呢?
You can't serialize a List<E>
, you need to transform to an Array
and use that when you pass a serialized object. 您无法序列化List<E>
,您需要转换为Array
并在传递序列化对象时使用它。 Then read out the array and transform into a list. 然后读出数组并转换成一个列表。 See this questions, it's about sortedset serialization E
also must be serializable. 看到这个问题,它是关于排序集序列化 E
也必须是可序列化的。
Look into .toArray
or putStringArray
either putStringArrayList
查看.toArray
或putStringArray
putStringArrayList
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.