我的程序基本上是一个项目列表,当你单击这些项目时,它会将你带到一个可展开的列表。问题是,我的条目列表有数百个条目,因此必须为每个条目创建一个不同的可扩展列表类变得单调乏味。相反,我希望根据按下的列表选项将不同的数组发送到一个子活动。
下面是我的主活动中发送信息的代码部分:
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); }下面是我的代码中应该接收它的部分:
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()等来实现我的可扩展列表。它编译得非常好。但是,每当我运行它并尝试单击列表项时,它都会显示进程意外停止。有人知道哪里出了问题吗?
发布于 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应该让自己成为可序列化的
https://stackoverflow.com/questions/5643877
复制相似问题