Android Parcelable create array

Posted by Ozik Abdullaev on Stack Overflow See other posts from Stack Overflow or by Ozik Abdullaev
Published on 2012-12-17T05:01:59Z Indexed on 2012/12/17 5:02 UTC
Read the original article Hit count: 230

Filed under:
|

In background i parse JSON, and then in this background i send Json to parcelable And in Parcelable i writestring with JSONObject.optString how i can write ArrayList?

List<Row> result = new ArrayList<Row>(array.length());
                for (int i = 0; i < array.length(); i++) {
                    result.add(new Row(array.optJSONObject(i)));
                }

Parcelable.java

public Row(JSONObject from) {
        thumb = from.optString(TAG_THUMBNAILS);
        bigImage = from.optString(TAG_BIG_IMAGE);
        author = from.optString(TAG_AUTHOR);
        description = from.optString(TAG_DESCRIPTION);
        date = from.optString(TAG_DATE);
    }

    public Row(Parcel parcel) {
        thumb = parcel.readString();
        bigImage = parcel.readString();
        author = parcel.readString();
        description = parcel.readString();
        date = parcel.readString();
    }

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

    @Override
    public void writeToParcel(Parcel parcel, int flags) {
        parcel.writeString(thumb);
        parcel.writeString(bigImage);
        parcel.writeString(author);
        parcel.writeString(description);
        parcel.writeString(date);
    }

© Stack Overflow or respective owner

Related posts about android

Related posts about parcelable