package com.ql.model;
import android.os.Parcel;
import android.os.Parcelable;
public class Stock implements Parcelable{
private String field_0;//代码+\n+名称
private String field_1;//最新+\n+金额
private String field_2;//涨幅
private String field_3;//涨跌
private String field_4;//雷达
//分时
private float[] field_5;//走势
private String field_6;//高点
private String field_7;//均线
private String field_8;//低点
public Stock(){
}
public Stock(String field_0, String field_1, String field_2,
String field_3, String field_4, float[] field_5, String field_6,
String field_7, String field_8) {
super();
this.field_0 = field_0;
this.field_1 = field_1;
this.field_2 = field_2;
this.field_3 = field_3;
this.field_4 = field_4;
this.field_5 = field_5;
this.field_6 = field_6;
this.field_7 = field_7;
this.field_8 = field_8;
}
public String getField_6() {
return field_6;
}
public void setField_6(String field_6) {
this.field_6 = field_6;
}
public String getField_7() {
return field_7;
}
public void setField_7(String field_7) {
this.field_7 = field_7;
}
public String getField_8() {
return field_8;
}
public void setField_8(String field_8) {
this.field_8 = field_8;
}
public float[] getField_5() {
return field_5;
}
public void setField_5(float[] field_5) {
this.field_5 = field_5;
}
public String getField_0() {
return field_0;
}
public void setField_0(String field_0) {
this.field_0 = field_0;
}
public String getField_1() {
return field_1;
}
public void setField_1(String field_1) {
this.field_1 = field_1;
}
public String getField_2() {
return field_2;
}
public void setField_2(String field_2) {
this.field_2 = field_2;
}
public String getField_3() {
return field_3;
}
public void setField_3(String field_3) {
this.field_3 = field_3;
}
public String getField_4() {
return field_4;
}
public void setField_4(String field_4) {
this.field_4 = field_4;
}
public static Parcelable.Creator getCreator() {
return CREATOR;
}
@Override
public int describeContents() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
// TODO Auto-generated method stub
dest.writeString(field_0);
dest.writeString(field_1);
dest.writeString(field_2);
dest.writeString(field_3);
dest.writeString(field_4);
dest.writeFloatArray(field_5);
dest.writeString(field_6);
dest.writeString(field_7);
dest.writeString(field_8);
}
public Stock(Parcel in)
{
this.field_0 = in.readString();
this.field_1 = in.readString();
this.field_2 = in.readString();
this.field_3 = in.readString();
this.field_4 = in.readString();
// in.readFloatArray(this.field_5);//似乎不行
this.field_5=in.createFloatArray();//可能不妥,看API
this.field_6 = in.readString();
this.field_7 = in.readString();
this.field_8 = in.readString();
}
@SuppressWarnings("unchecked")
public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
public Stock createFromParcel(Parcel in)
{
return new Stock(in);
}
public Stock[] newArray(int size)
{
return new Stock[size];
}
};
}
//ArrayList<Stock> models={XXXXXXX};
//Intent intent=new Intent(MyStockActivity.this,MyStockSettingActivity.class);
//传递
intent.putParcelableArrayListExtra("sockets", models);
//startActivityForResult(intent, RESULT_CODE_SETTING);
//读取
models=getIntent().getParcelableArrayListExtra("sockets");
Android高手进阶教程(十七)之---Android中Intent传递对象的两种方法(Serializable,Parcelable)!
传递图片和复杂对象,复杂对象也需要实现Parcelable接口
package com.ata.model.receive;
import android.graphics.Bitmap;
import android.os.Parcel;
import android.os.Parcelable;
public class Exam implements Parcelable{
public String ad_md5;//
public String buttons_md5;//
public String etx_code;//考试编码
public String faq_md5;//
public String is_etx;//0否1是
public String logo_url;//logourl
public Bitmap bitmap;//logo_url对应的图标
public String news_md5;//
public String sample_md5;//
public String sample_url;//邮汇样张url
public String sort;//
public String status;//状态
public String test_name;//考试名称
public String test_name_short;//
public String test_sponsor;//主办者
public String test_type;//考试类型
public String test_date;//当前批次考试日期
public String etx_id_desc;//当前批次说明
public String intro_url;//考试介绍url
public String test_notice;//考试提醒
public String date_url;//考试日期
public String etx_id;//
public int is_hot;//热门考试
public String account_notice;//帐号说明
public Bind bind;//复杂对象,绑定信息
public String getAccount_notice() {
return account_notice;
}
public void setAccount_notice(String account_notice) {
this.account_notice = account_notice;
}
public int getIs_hot() {
return is_hot;
}
public void setIs_hot(int is_hot) {
this.is_hot = is_hot;
}
public Bind getBind() {
return bind;
}
public void setBind(Bind bind) {
this.bind = bind;
}
public String getAd_md5() {
return ad_md5;
}
public void setAd_md5(String ad_md5) {
this.ad_md5 = ad_md5;
}
public String getButtons_md5() {
return buttons_md5;
}
public void setButtons_md5(String buttons_md5) {
this.buttons_md5 = buttons_md5;
}
public String getEtx_code() {
return etx_code;
}
public void setEtx_code(String etx_code) {
this.etx_code = etx_code;
}
public String getFaq_md5() {
return faq_md5;
}
public void setFaq_md5(String faq_md5) {
this.faq_md5 = faq_md5;
}
public String getIs_etx() {
return is_etx;
}
public void setIs_etx(String is_etx) {
this.is_etx = is_etx;
}
public String getLogo_url() {
return logo_url;
}
public void setLogo_url(String logo_url) {
this.logo_url = logo_url;
}
public String getNews_md5() {
return news_md5;
}
public void setNews_md5(String news_md5) {
this.news_md5 = news_md5;
}
public String getSample_md5() {
return sample_md5;
}
public void setSample_md5(String sample_md5) {
this.sample_md5 = sample_md5;
}
public String getSample_url() {
return sample_url;
}
public void setSample_url(String sample_url) {
this.sample_url = sample_url;
}
public String getSort() {
return sort;
}
public void setSort(String sort) {
this.sort = sort;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getTest_name() {
return test_name;
}
public void setTest_name(String test_name) {
this.test_name = test_name;
}
public String getTest_name_short() {
return test_name_short;
}
public void setTest_name_short(String test_name_short) {
this.test_name_short = test_name_short;
}
public String getTest_sponsor() {
return test_sponsor;
}
public void setTest_sponsor(String test_sponsor) {
this.test_sponsor = test_sponsor;
}
public String getTest_type() {
return test_type;
}
public void setTest_type(String test_type) {
this.test_type = test_type;
}
public String getTest_date() {
return test_date;
}
public void setTest_date(String test_date) {
this.test_date = test_date;
}
public String getEtx_id_desc() {
return etx_id_desc;
}
public void setEtx_id_desc(String etx_id_desc) {
this.etx_id_desc = etx_id_desc;
}
public String getIntro_url() {
return intro_url;
}
public void setIntro_url(String intro_url) {
this.intro_url = intro_url;
}
public String getTest_notice() {
return test_notice;
}
public void setTest_notice(String test_notice) {
this.test_notice = test_notice;
}
public String getDate_url() {
return date_url;
}
public void setDate_url(String date_url) {
this.date_url = date_url;
}
public String getEtx_id() {
return etx_id;
}
public void setEtx_id(String etx_id) {
this.etx_id = etx_id;
}
public Bitmap getBitmap() {
return bitmap;
}
public void setBitmap(Bitmap bitmap) {
this.bitmap = bitmap;
}
public static Parcelable.Creator<Exam> getCreator() {
return CREATOR;
}
public int describeContents() {
// TODO Auto-generated method stub
return 0;
}
public void writeToParcel(Parcel dest, int flags) {
// TODO Auto-generated method stub
dest.writeString(ad_md5);
dest.writeString(buttons_md5);
dest.writeString(etx_code);
dest.writeString(faq_md5);
dest.writeString(is_etx);
dest.writeString(logo_url);
bitmap.writeToParcel(dest, flags);
dest.writeString(news_md5);
dest.writeString(sample_md5);
dest.writeString(sample_url);
dest.writeString(sort);
dest.writeString(status);
dest.writeString(test_name);
dest.writeString(test_name_short);
dest.writeString(test_sponsor);
dest.writeString(test_type);
dest.writeString(test_date);
dest.writeString(etx_id_desc);
dest.writeString(intro_url);
dest.writeString(test_notice);
dest.writeString(date_url);
dest.writeString(etx_id);
dest.writeInt(is_hot);
dest.writeString(account_notice);
dest.writeParcelable(bind, flags);
}
public static final Parcelable.Creator<Exam> CREATOR = new Creator<Exam>() {
public Exam createFromParcel(Parcel source) {
Exam instance = new Exam();
instance.ad_md5 = source.readString();
instance.buttons_md5 = source.readString();
instance.etx_code = source.readString();
instance.faq_md5 = source.readString();
instance.is_etx = source.readString();
instance.logo_url = source.readString();
instance.bitmap=Bitmap.CREATOR.createFromParcel(source);
instance.news_md5 = source.readString();
instance.sample_md5 = source.readString();
instance.sample_url = source.readString();
instance.sort = source.readString();
instance.status = source.readString();
instance.test_name = source.readString();
instance.test_name_short = source.readString();
instance.test_sponsor = source.readString();
instance.test_type = source.readString();
instance.test_date = source.readString();
instance.etx_id_desc = source.readString();
instance.intro_url = source.readString();
instance.test_notice = source.readString();
instance.date_url = source.readString();
instance.etx_id = source.readString();
instance.is_hot = source.readInt();
instance.account_notice = source.readString();
instance.bind=source.readParcelable(Bind.class.getClassLoader());
return instance;
}
public Exam[] newArray(int size) {
// TODO Auto-generated method stub
return new Exam[size];
}
};
}
传递对象列表ArrayList<Queue>,Queue也要实现Parcelable
package com.reyo.model;
import java.util.ArrayList;
import android.os.Parcel;
import android.os.Parcelable;
public class QueueList implements Parcelable{
public String mealName;
public String startTime;
public String endTime;
public int timeType;
public int flagType;
public ArrayList<Queue> queueList;
public String getMealName() {
return mealName;
}
public void setMealName(String mealName) {
this.mealName = mealName;
}
public String getStartTime() {
return startTime;
}
public void setStartTime(String startTime) {
this.startTime = startTime;
}
public String getEndTime() {
return endTime;
}
public void setEndTime(String endTime) {
this.endTime = endTime;
}
public int getTimeType() {
return timeType;
}
public void setTimeType(int timeType) {
this.timeType = timeType;
}
public int getFlagType() {
return flagType;
}
public void setFlagType(int flagType) {
this.flagType = flagType;
}
public ArrayList<Queue> getQueueList() {
return queueList;
}
public void setQueueList(ArrayList<Queue> queueList) {
this.queueList = queueList;
}
public static Parcelable.Creator<QueueList> getCreator() {
return CREATOR;
}
public int describeContents() {
// TODO Auto-generated method stub
return 0;
}
public void writeToParcel(Parcel dest, int flags) {
// TODO Auto-generated method stub
dest.writeString(mealName);
dest.writeString(startTime);
dest.writeString(endTime);
dest.writeInt(timeType);
dest.writeInt(flagType);
dest.writeList(queueList);
}
public static final Parcelable.Creator<QueueList> CREATOR = new Creator<QueueList>() {
public QueueList createFromParcel(Parcel source) {
QueueList instance = new QueueList();
instance.mealName = source.readString();
instance.startTime = source.readString();
instance.endTime = source.readString();
instance.timeType = source.readInt();
instance.flagType = source.readInt();
instance.queueList=source.readArrayList(Queue.class.getClassLoader());
return instance;
}
public QueueList[] newArray(int size) {
// TODO Auto-generated method stub
return new QueueList[size];
}
};
}
Android中传递对象的三种方法
http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015/0104/2256.html