Android Parcelable Implementation with ArrayList<Object>

前端 未结 2 884
名媛妹妹
名媛妹妹 2021-01-18 06:41

so I am implementing a test app in which I will create a Tournament object as Parcelable and will pass them between intents. A tournament include: . A tournament name . Rule

2条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-18 06:48

    here is code that show you how parcle a arraylist

    public class ParcleListTopic implements Parcelable{
        private List list;
        private ArrayList listh=new ArrayList();
        public ArrayList GetListTopic()
        {
            for(int i=0;i list)
        {
            this.list=list;
        }
        public static final Parcelable.Creator CREATOR = new Parcelable.Creator(){
              public ParcleListTopic createFromParcel(Parcel s)
              {
                  return new ParcleListTopic(s);
              }
              public ParcleListTopic[] newArray(int size) 
              {
                    return new ParcleListTopic[size];
              }
        };
        public int describeContents() {
            // TODO Auto-generated method stub
            return 0;
        }
    }
    
    
    public class ParcleTopic implements Parcelable
    {
        HoldListTopic hold;
        public ParcleTopic(HoldListTopic hold)
        {
            this.hold=hold;
        }
        public HoldListTopic GetHold()
        {
            return hold;
        }
        public int describeContents() 
        {
            return 0;
        }
        public void writeToParcel(Parcel dest, int flags)
        {
            dest.writeString(hold.Title);
            dest.writeString(hold.Date);
            dest.writeInt(hold.NumberComment);
            dest.writeInt(hold.ID);
        }
        public ParcleTopic(Parcel in)
        {
            hold.Title=in.readString();
            hold.Date=in.readString();
            hold.NumberComment=in.readInt();
            hold.ID=in.readInt();
        }
        public static final Parcelable.Creator CREATOR = new Parcelable.Creator()
        {
              public ParcleTopic createFromParcel(Parcel s)
              {
                  return new ParcleTopic(s);
              }
              public ParcleTopic[] newArray(int size) 
              {
                    return new ParcleTopic[size];
              }
        }; }
    

提交回复
热议问题