-2

Possible Duplicate:
Help with passing ArrayList and parcelable Activity

I have already tried to use putExtra() but to no avail.

When I use putExtra(), there were syntax error. and the only way (it seems) is to convert the whole data selected to string. But the problem is, I only need to display part of the data and not all of it. therefore I think that is not the way.

What I am trying to do is to send an ArrayList of data. The first Activity is where the program search the Array for the data and the second Activity is for displaying part of the data.

I need to send the data onClick() of the ListView. And I need the data to be in ArrayList<Item>.

Before anyone answers or comment on this question more please take a look at my reputation. So with that much reputation I think you know that I am new. Just take that into consideration before downvoting.

Community
  • 1
  • 1
akemalFirdaus
  • 606
  • 1
  • 7
  • 15
  • This has been covered at length in at least five other questions ([here](http://stackoverflow.com/questions/5819238/help-with-passing-arraylist-and-parcelable-activity) is one such question, it links to others); start with Google... https://www.google.com/search?q=android+custom+arraylist+bundle – Cat Dec 31 '12 at 07:25
  • So why not make `Item` `Parcelable`? – stealthjong Dec 31 '12 at 07:38
  • @ChristiaandeJong I tried doing that but when i used parcelable, I cant display the result. I don't know what I am doing wrong – akemalFirdaus Dec 31 '12 at 09:10

1 Answers1

1

Assume you have a class like this, which implements Parcelable:

public class CustomParcelableClass implements Parcelable {
    public String string;
    public int i;

    @Override
    public int describeContents() {
        return hashCode();
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(i);
        dest.writeString(string);
    }

            private Item(Parcel in) {
             string= in.readString();
            }
}

and you make an Intent like this:

ArrayList<CustomParcelableClass> myParcelableList = 
          new ArrayList<CustomParcelableClass>();
myParcelableList.add(...);
...
yourIntent.putParcelableArrayListExtra(LIST, myParcelableList);

where LIST is something like:

public static final String LIST = "LIST";

and in your second class, in a method like onNewIntent(Intent i), retrieve your ArrayList through a line like

ArrayList<CustomParcelableClass> myParcelableList = 
        i.getExtras().getParcelableArrayList(LIST);

I do not know why this shouldn't work for you.

akemalFirdaus
  • 606
  • 1
  • 7
  • 15
stealthjong
  • 10,858
  • 13
  • 45
  • 84
  • Thank you for your response. I have tried to implement what you told but somehow when the program wants to go to the other activity, the program will crash due to an error `Javabinder, !!!FAILED BINDER TRANSACTION!!!`. There should not be any memory issue right? After all the data passed is just a line of text. – akemalFirdaus Jan 02 '13 at 06:55
  • @akemalFirdaus that has nothing to do with your initial problem. Google it and you'll find out. – stealthjong Jan 02 '13 at 08:33
  • Thank you, finally managed to do that.there was one method missing from your answer. I've already edited that. – akemalFirdaus Jan 03 '13 at 08:35