6

I'm trying to make my class parcelable, but it has a list of enums inside.

I've already seen how to do this with single enums here...

How could I do this?

Thanks! ;)

4

1 に答える 1

13

さて、前に引用したリンクの情報を使用してこれを解決しました。

それが私がしたことでした:

public enum Improvement {ENUM1, ENUM2, etc}

public void writeToParcel(Parcel dest, int flags) {
    ...
    List<String> improvementStrings = new ArrayList<String>();
    for (Improvement improvement : improvements) {
        improvementStrings.add(improvement.name());
    }
    dest.writeList(improvementStrings);
}

public void readFromParcel(Parcel in) {
    ...
    List<String> improvementStrings = new ArrayList<String>();
    in.readList(improvementStrings, null);
    for (String improvementString : improvementStrings) {
        improvements.add(Improvement.valueOf(improvementString));
    }
}
于 2013-02-22T12:31:40.380 に答える