首页 > 学院 > 开发设计 > 正文

Parcealbe传递数据

2019-11-09 16:05:49
字体:
来源:转载
供稿:网友
     
  调用方法:                               
ArrayList<TopicSubBean> topicSubBeanArrayList=new ArrayList<TopicSubBean>();Parcel parcel=Parcel.obtain();for(int i=0;i<subBeanList.size();i++){    TopicSubBean topicSubBean=TopicSubBean.CREATOR.createFromParcel(parcel);    topicSubBean.desc=subBeanList.get(i).desc;    topicSubBeanArrayList.add(topicSubBean);}parcel.recycle();实体类
public class TopicSubBean implements Parcelable{    public String imgUrl;  /*  public String videoUrl;    public  int height;    public int width;*/    public String desc;    @Override    public int describeContents() {        return 0;    }    @Override    public void writeToParcel(Parcel dest, int flags) {        dest.writeString(imgUrl);        dest.writeString(desc);    }    public static final Creator<TopicSubBean> CREATOR = new Creator<TopicSubBean>() {        @Override        public TopicSubBean createFromParcel(Parcel in) {            return new TopicSubBean(in);        }        @Override        public TopicSubBean[] newArray(int size) {            return new TopicSubBean[size];        }    };    PRotected TopicSubBean(Parcel in) {        imgUrl = in.readString();        desc = in.readString();    }}

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表