Parcelable传递图片,复杂对象,对象列表

Java代码   收藏代码
  1. package com.ql.model;  
  2.   
  3. import android.os.Parcel;  
  4. import android.os.Parcelable;  
  5.   
  6. public class Stock implements Parcelable{  
  7.   
  8.     private String field_0;//代码+\n+名称  
  9.     private String field_1;//最新+\n+金额  
  10.     private String field_2;//涨幅  
  11.     private String field_3;//涨跌  
  12.     private String field_4;//雷达  
  13.     //分时  
  14.     private float[] field_5;//走势  
  15.     private String field_6;//高点  
  16.     private String field_7;//均线  
  17.     private String field_8;//低点  
  18.     public Stock(){  
  19.           
  20.     }  
  21.     public Stock(String field_0, String field_1, String field_2,  
  22.             String field_3, String field_4, float[] field_5, String field_6,  
  23.             String field_7, String field_8) {  
  24.         super();  
  25.         this.field_0 = field_0;  
  26.         this.field_1 = field_1;  
  27.         this.field_2 = field_2;  
  28.         this.field_3 = field_3;  
  29.         this.field_4 = field_4;  
  30.         this.field_5 = field_5;  
  31.         this.field_6 = field_6;  
  32.         this.field_7 = field_7;  
  33.         this.field_8 = field_8;  
  34.     }  
  35.     public String getField_6() {  
  36.         return field_6;  
  37.     }  
  38.     public void setField_6(String field_6) {  
  39.         this.field_6 = field_6;  
  40.     }  
  41.     public String getField_7() {  
  42.         return field_7;  
  43.     }  
  44.     public void setField_7(String field_7) {  
  45.         this.field_7 = field_7;  
  46.     }  
  47.     public String getField_8() {  
  48.         return field_8;  
  49.     }  
  50.     public void setField_8(String field_8) {  
  51.         this.field_8 = field_8;  
  52.     }  
  53.     public float[] getField_5() {  
  54.         return field_5;  
  55.     }  
  56.     public void setField_5(float[] field_5) {  
  57.         this.field_5 = field_5;  
  58.     }  
  59.     public String getField_0() {  
  60.         return field_0;  
  61.     }  
  62.     public void setField_0(String field_0) {  
  63.         this.field_0 = field_0;  
  64.     }  
  65.     public String getField_1() {  
  66.         return field_1;  
  67.     }  
  68.     public void setField_1(String field_1) {  
  69.         this.field_1 = field_1;  
  70.     }  
  71.     public String getField_2() {  
  72.         return field_2;  
  73.     }  
  74.     public void setField_2(String field_2) {  
  75.         this.field_2 = field_2;  
  76.     }  
  77.     public String getField_3() {  
  78.         return field_3;  
  79.     }  
  80.     public void setField_3(String field_3) {  
  81.         this.field_3 = field_3;  
  82.     }  
  83.     public String getField_4() {  
  84.         return field_4;  
  85.     }  
  86.     public void setField_4(String field_4) {  
  87.         this.field_4 = field_4;  
  88.     }  
  89.     public static Parcelable.Creator getCreator() {  
  90.         return CREATOR;  
  91.     }  
  92.     @Override  
  93.     public int describeContents() {  
  94.         // TODO Auto-generated method stub  
  95.         return 0;  
  96.     }  
  97.     @Override  
  98.     public void writeToParcel(Parcel dest, int flags) {  
  99.         // TODO Auto-generated method stub  
  100.         dest.writeString(field_0);    
  101.         dest.writeString(field_1);    
  102.         dest.writeString(field_2);    
  103.         dest.writeString(field_3);    
  104.         dest.writeString(field_4);  
  105.         dest.writeFloatArray(field_5);  
  106.         dest.writeString(field_6);  
  107.         dest.writeString(field_7);  
  108.         dest.writeString(field_8);  
  109.     }  
  110.     public Stock(Parcel in)    
  111.     {    
  112.         this.field_0 = in.readString();    
  113.         this.field_1 = in.readString();    
  114.         this.field_2 = in.readString();  
  115.         this.field_3 = in.readString();  
  116.         this.field_4 = in.readString();  
  117. //        in.readFloatArray(this.field_5);//似乎不行  
  118.         this.field_5=in.createFloatArray();//可能不妥,看API  
  119.         this.field_6 = in.readString();  
  120.         this.field_7 = in.readString();  
  121.         this.field_8 = in.readString();  
  122.     }    
  123.      
  124.     @SuppressWarnings("unchecked")    
  125.     public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {    
  126.         public Stock createFromParcel(Parcel in)    
  127.         {    
  128.             return new Stock(in);    
  129.         }    
  130.      
  131.         public Stock[] newArray(int size)    
  132.         {    
  133.             return new Stock[size];    
  134.         }    
  135.     };    
  136. }  

Java代码   收藏代码
  1. //ArrayList<Stock> models={XXXXXXX};  
  2. //Intent intent=new Intent(MyStockActivity.this,MyStockSettingActivity.class);  
  3. //传递  
  4. intent.putParcelableArrayListExtra("sockets", models);  
  5. //startActivityForResult(intent, RESULT_CODE_SETTING);  
  6. //读取  
  7. models=getIntent().getParcelableArrayListExtra("sockets");  


Android高手进阶教程(十七)之---Android中Intent传递对象的两种方法(Serializable,Parcelable)! 
http://blog.csdn.net/Android_Tutor/archive/2010/07/16/5740845.aspx 

传递图片和复杂对象,复杂对象也需要实现Parcelable接口 
Java代码   收藏代码
  1. package com.ata.model.receive;  
  2.   
  3. import android.graphics.Bitmap;  
  4. import android.os.Parcel;  
  5. import android.os.Parcelable;  
  6.   
  7. public class Exam implements Parcelable{  
  8.   
  9.     public String ad_md5;//  
  10.     public String buttons_md5;//  
  11.     public String etx_code;//考试编码  
  12.     public String faq_md5;//  
  13.     public String is_etx;//0否1是  
  14.     public String logo_url;//logourl  
  15.     public Bitmap bitmap;//logo_url对应的图标  
  16.     public String news_md5;//  
  17.     public String sample_md5;//  
  18.     public String sample_url;//邮汇样张url  
  19.     public String sort;//  
  20.     public String status;//状态  
  21.     public String test_name;//考试名称  
  22.     public String test_name_short;//  
  23.     public String test_sponsor;//主办者  
  24.     public String test_type;//考试类型  
  25.     public String test_date;//当前批次考试日期  
  26.     public String etx_id_desc;//当前批次说明  
  27.     public String intro_url;//考试介绍url  
  28.     public String test_notice;//考试提醒  
  29.     public String date_url;//考试日期  
  30.     public String etx_id;//  
  31.     public int is_hot;//热门考试  
  32.     public String account_notice;//帐号说明  
  33.     public Bind bind;//复杂对象,绑定信息  
  34.   
  35.     public String getAccount_notice() {  
  36.         return account_notice;  
  37.     }  
  38.     public void setAccount_notice(String account_notice) {  
  39.         this.account_notice = account_notice;  
  40.     }  
  41.     public int getIs_hot() {  
  42.         return is_hot;  
  43.     }  
  44.     public void setIs_hot(int is_hot) {  
  45.         this.is_hot = is_hot;  
  46.     }  
  47.     public Bind getBind() {  
  48.         return bind;  
  49.     }  
  50.     public void setBind(Bind bind) {  
  51.         this.bind = bind;  
  52.     }  
  53.     public String getAd_md5() {  
  54.         return ad_md5;  
  55.     }  
  56.     public void setAd_md5(String ad_md5) {  
  57.         this.ad_md5 = ad_md5;  
  58.     }  
  59.     public String getButtons_md5() {  
  60.         return buttons_md5;  
  61.     }  
  62.     public void setButtons_md5(String buttons_md5) {  
  63.         this.buttons_md5 = buttons_md5;  
  64.     }  
  65.     public String getEtx_code() {  
  66.         return etx_code;  
  67.     }  
  68.     public void setEtx_code(String etx_code) {  
  69.         this.etx_code = etx_code;  
  70.     }  
  71.     public String getFaq_md5() {  
  72.         return faq_md5;  
  73.     }  
  74.     public void setFaq_md5(String faq_md5) {  
  75.         this.faq_md5 = faq_md5;  
  76.     }  
  77.     public String getIs_etx() {  
  78.         return is_etx;  
  79.     }  
  80.     public void setIs_etx(String is_etx) {  
  81.         this.is_etx = is_etx;  
  82.     }  
  83.     public String getLogo_url() {  
  84.         return logo_url;  
  85.     }  
  86.     public void setLogo_url(String logo_url) {  
  87.         this.logo_url = logo_url;  
  88.     }  
  89.     public String getNews_md5() {  
  90.         return news_md5;  
  91.     }  
  92.     public void setNews_md5(String news_md5) {  
  93.         this.news_md5 = news_md5;  
  94.     }  
  95.     public String getSample_md5() {  
  96.         return sample_md5;  
  97.     }  
  98.     public void setSample_md5(String sample_md5) {  
  99.         this.sample_md5 = sample_md5;  
  100.     }  
  101.     public String getSample_url() {  
  102.         return sample_url;  
  103.     }  
  104.     public void setSample_url(String sample_url) {  
  105.         this.sample_url = sample_url;  
  106.     }  
  107.     public String getSort() {  
  108.         return sort;  
  109.     }  
  110.     public void setSort(String sort) {  
  111.         this.sort = sort;  
  112.     }  
  113.     public String getStatus() {  
  114.         return status;  
  115.     }  
  116.     public void setStatus(String status) {  
  117.         this.status = status;  
  118.     }  
  119.     public String getTest_name() {  
  120.         return test_name;  
  121.     }  
  122.     public void setTest_name(String test_name) {  
  123.         this.test_name = test_name;  
  124.     }  
  125.     public String getTest_name_short() {  
  126.         return test_name_short;  
  127.     }  
  128.     public void setTest_name_short(String test_name_short) {  
  129.         this.test_name_short = test_name_short;  
  130.     }  
  131.     public String getTest_sponsor() {  
  132.         return test_sponsor;  
  133.     }  
  134.     public void setTest_sponsor(String test_sponsor) {  
  135.         this.test_sponsor = test_sponsor;  
  136.     }  
  137.     public String getTest_type() {  
  138.         return test_type;  
  139.     }  
  140.     public void setTest_type(String test_type) {  
  141.         this.test_type = test_type;  
  142.     }  
  143.     public String getTest_date() {  
  144.         return test_date;  
  145.     }  
  146.     public void setTest_date(String test_date) {  
  147.         this.test_date = test_date;  
  148.     }  
  149.     public String getEtx_id_desc() {  
  150.         return etx_id_desc;  
  151.     }  
  152.     public void setEtx_id_desc(String etx_id_desc) {  
  153.         this.etx_id_desc = etx_id_desc;  
  154.     }  
  155.     public String getIntro_url() {  
  156.         return intro_url;  
  157.     }  
  158.     public void setIntro_url(String intro_url) {  
  159.         this.intro_url = intro_url;  
  160.     }  
  161.     public String getTest_notice() {  
  162.         return test_notice;  
  163.     }  
  164.     public void setTest_notice(String test_notice) {  
  165.         this.test_notice = test_notice;  
  166.     }  
  167.     public String getDate_url() {  
  168.         return date_url;  
  169.     }  
  170.     public void setDate_url(String date_url) {  
  171.         this.date_url = date_url;  
  172.     }  
  173.     public String getEtx_id() {  
  174.         return etx_id;  
  175.     }  
  176.     public void setEtx_id(String etx_id) {  
  177.         this.etx_id = etx_id;  
  178.     }  
  179.       
  180.     public Bitmap getBitmap() {  
  181.         return bitmap;  
  182.     }  
  183.     public void setBitmap(Bitmap bitmap) {  
  184.         this.bitmap = bitmap;  
  185.     }  
  186.     public static Parcelable.Creator<Exam> getCreator() {  
  187.         return CREATOR;  
  188.     }  
  189.     public int describeContents() {  
  190.         // TODO Auto-generated method stub  
  191.         return 0;  
  192.     }  
  193.     public void writeToParcel(Parcel dest, int flags) {  
  194.         // TODO Auto-generated method stub  
  195.         dest.writeString(ad_md5);  
  196.         dest.writeString(buttons_md5);  
  197.         dest.writeString(etx_code);  
  198.         dest.writeString(faq_md5);  
  199.         dest.writeString(is_etx);  
  200.         dest.writeString(logo_url);  
  201.         bitmap.writeToParcel(dest, flags);  
  202.         dest.writeString(news_md5);  
  203.         dest.writeString(sample_md5);  
  204.         dest.writeString(sample_url);  
  205.         dest.writeString(sort);  
  206.         dest.writeString(status);  
  207.         dest.writeString(test_name);  
  208.         dest.writeString(test_name_short);  
  209.         dest.writeString(test_sponsor);  
  210.         dest.writeString(test_type);  
  211.         dest.writeString(test_date);  
  212.         dest.writeString(etx_id_desc);  
  213.         dest.writeString(intro_url);  
  214.         dest.writeString(test_notice);  
  215.         dest.writeString(date_url);  
  216.         dest.writeString(etx_id);  
  217.         dest.writeInt(is_hot);  
  218.         dest.writeString(account_notice);  
  219.         dest.writeParcelable(bind, flags);  
  220.     }  
  221.     public static final Parcelable.Creator<Exam> CREATOR = new Creator<Exam>() {  
  222.         public Exam createFromParcel(Parcel source) {  
  223.             Exam instance = new Exam();  
  224.             instance.ad_md5 = source.readString();  
  225.             instance.buttons_md5 = source.readString();  
  226.             instance.etx_code = source.readString();  
  227.             instance.faq_md5 = source.readString();  
  228.             instance.is_etx = source.readString();  
  229.             instance.logo_url = source.readString();  
  230.             instance.bitmap=Bitmap.CREATOR.createFromParcel(source);  
  231.             instance.news_md5 = source.readString();  
  232.             instance.sample_md5 = source.readString();  
  233.             instance.sample_url = source.readString();  
  234.             instance.sort = source.readString();  
  235.             instance.status = source.readString();  
  236.             instance.test_name = source.readString();  
  237.             instance.test_name_short = source.readString();  
  238.             instance.test_sponsor = source.readString();  
  239.             instance.test_type = source.readString();  
  240.             instance.test_date = source.readString();  
  241.             instance.etx_id_desc = source.readString();  
  242.             instance.intro_url = source.readString();  
  243.             instance.test_notice = source.readString();  
  244.             instance.date_url = source.readString();  
  245.             instance.etx_id = source.readString();  
  246.             instance.is_hot = source.readInt();  
  247.             instance.account_notice = source.readString();  
  248.             instance.bind=source.readParcelable(Bind.class.getClassLoader());  
  249.             return instance;  
  250.         }  
  251.   
  252.         public Exam[] newArray(int size) {  
  253.             // TODO Auto-generated method stub  
  254.             return new Exam[size];  
  255.         }  
  256.     };  
  257.       
  258. }  


传递对象列表ArrayList<Queue>,Queue也要实现Parcelable 
Java代码   收藏代码
  1. package com.reyo.model;  
  2.   
  3. import java.util.ArrayList;  
  4.   
  5. import android.os.Parcel;  
  6. import android.os.Parcelable;  
  7.   
  8. public class QueueList implements Parcelable{  
  9.   
  10.     public String mealName;  
  11.     public String startTime;  
  12.     public String endTime;  
  13.     public int timeType;  
  14.     public int flagType;  
  15.     public ArrayList<Queue> queueList;  
  16.     public String getMealName() {  
  17.         return mealName;  
  18.     }  
  19.     public void setMealName(String mealName) {  
  20.         this.mealName = mealName;  
  21.     }  
  22.     public String getStartTime() {  
  23.         return startTime;  
  24.     }  
  25.     public void setStartTime(String startTime) {  
  26.         this.startTime = startTime;  
  27.     }  
  28.     public String getEndTime() {  
  29.         return endTime;  
  30.     }  
  31.     public void setEndTime(String endTime) {  
  32.         this.endTime = endTime;  
  33.     }  
  34.     public int getTimeType() {  
  35.         return timeType;  
  36.     }  
  37.     public void setTimeType(int timeType) {  
  38.         this.timeType = timeType;  
  39.     }  
  40.     public int getFlagType() {  
  41.         return flagType;  
  42.     }  
  43.     public void setFlagType(int flagType) {  
  44.         this.flagType = flagType;  
  45.     }  
  46.     public ArrayList<Queue> getQueueList() {  
  47.         return queueList;  
  48.     }  
  49.     public void setQueueList(ArrayList<Queue> queueList) {  
  50.         this.queueList = queueList;  
  51.     }  
  52.       
  53.     public static Parcelable.Creator<QueueList> getCreator() {  
  54.         return CREATOR;  
  55.     }  
  56.     public int describeContents() {  
  57.         // TODO Auto-generated method stub  
  58.         return 0;  
  59.     }  
  60.     public void writeToParcel(Parcel dest, int flags) {  
  61.         // TODO Auto-generated method stub  
  62.         dest.writeString(mealName);  
  63.         dest.writeString(startTime);  
  64.         dest.writeString(endTime);  
  65.         dest.writeInt(timeType);  
  66.         dest.writeInt(flagType);  
  67.         dest.writeList(queueList);  
  68.     }  
  69.     public static final Parcelable.Creator<QueueList> CREATOR = new Creator<QueueList>() {  
  70.         public QueueList createFromParcel(Parcel source) {  
  71.             QueueList instance = new QueueList();  
  72.             instance.mealName = source.readString();  
  73.             instance.startTime = source.readString();  
  74.             instance.endTime = source.readString();  
  75.             instance.timeType = source.readInt();  
  76.             instance.flagType = source.readInt();  
  77.             instance.queueList=source.readArrayList(Queue.class.getClassLoader());  
  78.             return instance;  
  79.         }  
  80.   
  81.         public QueueList[] newArray(int size) {  
  82.             // TODO Auto-generated method stub  
  83.             return new QueueList[size];  
  84.         }  
  85.     };  
  86.       
  87. }  
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值