Passing Arrays to a SubActivity?

Put your problem here if it does not fit any of the other categories.

Passing Arrays to a SubActivity?

Postby k_kin » Wed Apr 13, 2011 3:41 am

My program is basically a list of items, and when you click the items it sends you to an expandable list. The problem is, my list of items is hundreds of items long, so it becomes tedious to have to make a different expandable list class for each one. Instead, I want to send different arrays to one subactivity depending on which list option was pressed.

Here's the part of my code in my main activity that is supposed to send the info:
Code: Select all
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); }


Here's the part of my code that is supposed to receive it:
Code: Select all
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");   


I go on to try to use createParentList()/createChildList(), etc for my expandable list. It compiles perfectly fine. However, whenever I run it and try to click on the list item, it says that the process has stopped unexpectedly. Does anyone know what is wrong?
k_kin
Once Poster
Once Poster
 
Posts: 1
Joined: Wed Apr 13, 2011 3:21 am

Top

Re: Passing Arrays to a SubActivity?

Postby AedonEtLIRA » Mon Apr 18, 2011 11:14 pm

Could you post the stack trace?
Walk with purpose, and build something.
User avatar
AedonEtLIRA
Senior Developer
Senior Developer
 
Posts: 146
Joined: Wed Jul 28, 2010 11:52 pm

Re: Passing Arrays to a SubActivity?

Postby AedonEtLIRA » Mon Apr 18, 2011 11:18 pm

I'm thinking it's a cast error. I'm unable to check right now, but I think you cant use a [][] as an extra. Although from the looks of things, you don't even need a double array. I would try using a single array and see if that fixes it up for you. If not, like I said earlier, post your stack trace.
Walk with purpose, and build something.
User avatar
AedonEtLIRA
Senior Developer
Senior Developer
 
Posts: 146
Joined: Wed Jul 28, 2010 11:52 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 20 guests