9

Parcelable私はParcelable Classのすべてのフィールドの実用的な実装を持っています.List<List<String>>

class Employee implements Parcelable {

    List<List<String>> details;
    //.......

    protected Employee(Parcel in) {
        details = new ArrayList<List<String>>();
        // i know this is wrong just posting to clarify
        in.readList(details, List.class.getClassLoader());
        //......
    }

    public void writeToParcel(Parcel dest, int flags) {
        dest.writeList(details);
        //.....
    }

    public int describeContents() {
        return 0;
    }

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

        public Employee[] newArray(int size) {
            return new Employee[size];
        }
    };

}

例外:

05-10 19:07:44.072: E/AndroidRuntime(10661): Caused by: java.lang.RuntimeException: Parcel android.os.Parcel@42a509e8: Unmarshalling unknown type code 3604535 at offset 268
4

3 に答える 3

8

それを拡張ArrayListして実装Parcelableすることは私にとってはうまくいきました。

public class ParcelableArrayList extends ArrayList<String> implements 
        Parcelable {

    private static final long serialVersionUID = -8516873361351845306L;

    public ParcelableArrayList(){
        super();
    }

    protected ParcelableArrayList(Parcel in) {
        in.readList(this, String.class.getClassLoader());
    }

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

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeList(this);
    }   

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

        public ParcelableArrayList[] newArray(int size) {
            return new ParcelableArrayList[size];
        }
    };

}

従業員クラス

class Employee implements Parcelable {

    List<ParcelableArrayList> details;
    //.......

    protected Employee(Parcel in) {
        details = new ArrayList<ParcelableArrayList>();
        in.readTypedList(details,ParcelableArrayList.CREATOR);
        //......
    }

    public void writeToParcel(Parcel dest, int flags) {
        dest.writeList(details);
        //.....
    }

    public int describeContents() {
        return 0;
    }

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

        public Employee[] newArray(int size) {
            return new Employee[size];
        }
    };

}
于 2013-05-13T19:08:48.217 に答える
0

I would create a class that extends List, implement Parcelable on that class. You can otherwise treat it as a normal list, but allow it to be parcelable.

于 2013-05-11T02:33:10.757 に答える
0

class DetailsEntry implements Parcelablewhich containsを作成してList<String>で使用List<DetailsEntry> detailsEmployeeます。

于 2013-05-11T08:09:44.970 に答える