将带有对象的 ArrayList 传递给新的 Activity? [英] Passing ArrayList with objects to new Activity?

查看:26
本文介绍了将带有对象的 ArrayList 传递给新的 Activity?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 ArrayList 从我的第一个 Activity 传递到下一个.基本上,第一个活动解析一个 XML 文件并创建一个包含对象的 ArrayList.我想要做的是将该 ArrayList 发送到我的第二个活动,并在 ListView 中显示一些对象数据.

I'm trying to pass an ArrayList from my first Activity to the next one. Basically, the first activity parses an XML file and creates an ArrayList with objects inside. What I want to do is send that ArrayList to my second activity and show some of the object data in a ListView.

我想用一个意图来做这件事,但看起来只有原始数据类型通常通过意图传递.对吗?

I thought of doing this with an intent, but it looks like only primitive datatypes are usually passed through intents. Is this right?

如果是这样,传递数据的更好解决方案是什么?当然,Android 必须提供一些东西才能做这种事情.

If so, what would be a better solution to pass the data? Certainly Android must provide something to be able to do this kind of thing.

非常感谢任何帮助/代码示例..

Any help/code examples are really appreciated..

谢谢

我通过首先创建和调用意图解决了这个问题,并且只解析我调用的活动中的 XML.这样我就不需要再传递对象了.但是对于那些感兴趣的人,您可以在此处阅读有关如何通过活动传递数据的信息.

推荐答案

复杂类型可以通过 Parcelable 传递.这个问题中的一个例子:

Complex types may be passed by means of Parcelable. An example is in this question:

帮助传递 ArrayList 和parcelable Activity

这篇关于将带有对象的 ArrayList 传递给新的 Activity?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆