简体   繁体   English

如何将arrayadapter传递给另一个活动?

[英]How can I pass an arrayadapter to another activity?

Basically I'm making a battleships game with a messaging system. 基本上,我正在使用消息传递系统制作战舰游戏。 Therefore I've got another activity that the user can switch back and forth from. 因此,我进行了另一个活动,用户可以从中来回切换。 So if phone 1 sends a message to phone 2, phone 2 will add the message to an array adapter and then pass that to the new activity when the user goes to the message page. 因此,如果电话1向电话2发送消息,则电话2会将消息添加到阵列适配器,然后在用户转到消息页面时将其传递给新活动。 I hope this makes sense. 我希望这是有道理的。

How can I send my arrayadapter to another activity? 如何将我的arrayadapter发送到另一个活动? Is it something like intent.putExtra(etc); 是否像intent.putExtra(etc); . Do I need to save it to an arraylist and convert that to an array adapter in the new activity? 我是否需要将其保存到arraylist并将其转换为新活动中的阵列适配器?

I would say you should simply pass the underlying data to the other Activity, and have the arrayadapter reload the data. 我要说的是,您应该简单地将基础数据传递给另一个Activity,并让arrayadapter重新加载数据。 The ArrayAdapter is initialized with the context of the Activity you loaded it with. ArrayAdapter会使用您加载它的Activity的上下文进行初始化。

The simplest you can do is make the ArrayAdapter serializable. 您最简单的方法是使ArrayAdapter可序列化。 Just implement the interface. 只需实现接口即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 arrayadapter 中获取值以将其传递给另一个活动 - How can I get value from an arrayadapter to pass it another activity 如何从另一个活动调用 ArrayAdapter 以使用 strings.xml 数组从 ArrayAdapter 中删除项目? - How can I call an ArrayAdapter from another activity to delete item from ArrayAdapter with strings.xml array? 如何将上下文从活动传递到不是活动的另一个类中的ArrayAdapter? - How do I pass in a context from an activity to an ArrayAdapter in another class that's not an activity? 如何将图像从活动传递到Android中的另一个活动? - How can I pass an image from an activity to another activity in Android? 如何将数据正确地从一项活动传递到另一项活动? - how can I pass data correctly from one activity to another? 如何将 Bitmap 对象从一个活动传递到另一个活动 - How can I pass a Bitmap object from one activity to another 如何将 RadioGroup 从一项活动传递到另一项活动? - How can I pass a RadioGroup from one activity to another one? 如何将图像数组传递给另一个活动? - How can I pass array of images to another activity? 如何将单击的按钮上的文本传递给另一个活动? - How can I pass the text on the button which was clicked to another Activity? 如何从listview获取变量并传递给另一个活动? - How can i get variable from listview and pass to another activity?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM