首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何将数组传递给子活动(android)?

如何将数组传递给子活动(android)?
EN

Stack Overflow用户
提问于 2011-04-13 10:55:03
回答 1查看 155关注 0票数 0

我的程序基本上是一个项目列表,当你单击这些项目时,它会将你带到一个可展开的列表。问题是,我的条目列表有数百个条目,因此必须为每个条目创建一个不同的可扩展列表类变得单调乏味。相反,我希望根据按下的列表选项将不同的数组发送到一个子活动。

下面是我的主活动中发送信息的代码部分:

代码语言:javascript
运行
复制
if ((String) ((TextView) view).getText() == "Name of List Item") {
               Intent myIntent = new Intent(view.getContext(),
                     SubActivity.class);
               myIntent.putExtra("parents", new String[] { "bunch of parents" });
               myIntent.putExtra("children", new String[][] {
                           { "bunch" },
                           { "of" },
                           { "children"} });
               startActivityForResult(myIntent, 0); }

下面是我的代码中应该接收它的部分:

代码语言:javascript
运行
复制
String[] parents;              //declared outside onCreate() so they can be used by methods like createParentList()
String[][] children;

public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);

      Bundle b = this.getIntent().getExtras();

      moves = b.getStringArray("parents");
      parents = (String[][]) b.getSerializable("children");   

我继续尝试使用createParentList()、/createChildList()等来实现我的可扩展列表。它编译得非常好。但是,每当我运行它并尝试单击列表项时,它都会显示进程意外停止。有人知道哪里出了问题吗?

EN

回答 1

Stack Overflow用户

发布于 2011-04-13 11:00:02

我认为您应该看到http://shri.blog.kraya.co.uk/2010/04/26/android-parcel-data-to-pass-between-activities-using-parcelable-classes/,或者Transferring object data from one activity to another activity .you应该让自己成为可序列化的

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5643877

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档