0

Is there a short easy way to store/recall an arraylist of an arraylist? Currently, I have an ArrayList. I was able to successfully use outState.putParcelableArrayList to store an ArrayList with the onSaveInstanceState. However, the arraylist of an arraylist has me stumped. Do I need to create an entirely new class? Or is there another method that would be a lot easier to store it?

Here's the current code for my object. I simplified it.

public class Tree implements Parcelable{
int length1;

public Tree(int length)
{
length1 = length;   
}


public int getLength1()
{
    return length1;
}


public Tree(Parcel in)
{
    readFromParcel(in);
}

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

@Override
public void writeToParcel(Parcel out, int flags) {
    out.writeInt(length1);
}

private void readFromParcel(Parcel in) {
    length1 = in.readInt();
}

public static final Parcelable.Creator<Tree> CREATOR
= new Parcelable.Creator<MyObject>() {
    @Override
    public Tree createFromParcel(Parcel in) {
        return new Tree(in);
    }

    @Override
    public Tree[] newArray(int size) {
        return new Tree[size];
    }
};
}

Then in my activity, I have ArrayList trees and then ArrayList> badTrees. For storing the single ArrayList trees, I just use putParcelableArrayList and savedInstanceState.getParcelableArrayList for trees. Is it possible to do the same for an array of an array? Thanks a lot.

lclankyo
  • 221
  • 3
  • 10
  • make a json out of it and reload it (gson is a good lib) – A.S. Mar 19 '15 at 10:04
  • I'm really new to programming, so I'm not too familiar about how I would go about doing those things, but I'll do some searches. Thanks a lot for the suggestion. – lclankyo Mar 20 '15 at 19:46

0 Answers0