0

I have a model class which implement Parcelable and 2 string and one arraylist of another model class

i can retrive title1 and title2 but i am not able to retrive option4 arraylist its get null

`public class TopListSubListModel implements Parcelable { String title1,title2; ArrayList option4;

public TopListSubListModel(String title1, String title2, ArrayList<Option4Model> option4) {
    this.title1 = title1;
    this.title2 = title2;
    this.option4 = option4;
}

protected TopListSubListModel(Parcel in) {
    title1 = in.readString();
    title2 = in.readString();
}

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

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

public String getTitle1() {
    return title1;
}

public void setTitle1(String title1) {
    this.title1 = title1;
}

public String getTitle2() {
    return title2;
}

public void setTitle2(String title2) {
    this.title2 = title2;
}

public ArrayList<Option4Model> getOption4() {
    return option4;
}

public void setOption4(ArrayList<Option4Model> option4) {
    this.option4 = option4;
}

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

@Override
public void writeToParcel(Parcel parcel, int i) {
    parcel.writeString(title1);
    parcel.writeString(title2);
}

}`

  • Here is answer : https://stackoverflow.com/questions/22446359/android-class-parcelable-with-arraylist – RZ_ Oct 05 '22 at 13:57

0 Answers0