Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a list<enum> parcelable? [closed]

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! ;)

like image 635
mvalencaa Avatar asked Feb 22 '13 03:02

mvalencaa


1 Answers

Ok, I solved this just using the information at the link cited before.

That was what I did:

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));
    }
}
like image 72
mvalencaa Avatar answered Sep 18 '22 00:09

mvalencaa