常用鏈接

          統(tǒng)計(jì)

          最新評(píng)論

          Activitie之間傳對(duì)象,通過(guò)Parcelable(轉(zhuǎn))

          對(duì)象必須實(shí)現(xiàn)Serializable,對(duì)象代碼如下:

          Java代碼 
          1. import java.io.Serializable;  
          2.   
          3. import android.graphics.drawable.Drawable;  
          4.   
          5. /** 
          6.  * 包括軟件信息及評(píng)論 
          7.  * */  
          8. public class MyApplicationInfo extends Object implements Serializable{  
          9.       
          10.     /** 
          11.      *  
          12.      */  
          13.     private static final long serialVersionUID = -5151302508106116740L;  
          14.   
          15.     //程序名稱  
          16.     private String title;  
          17.       
          18.     //程序名稱  
          19.     private String label;  
          20.       
          21.     //程序版本  
          22.     private String version;  
          23.       
          24.     //新版本  
          25.     private String newVersion;  
          26.       
          27.     //內(nèi)容介紹  
          28.     private String content;  
          29.       
          30.     //作者  
          31.     private String author;  
          32.       
          33.     //圖標(biāo)鏈接  
          34.     private String icon;  
          35.       
          36.     //圖標(biāo)  
          37.     private Drawable dicon;  
          38.       
          39.     //演示圖片動(dòng)態(tài)數(shù)組  
          40.     private String[] Demos;  
          41.       
          42.     //價(jià)格  
          43.     private String price;  
          44.       
          45.     //總共5星,以數(shù)字形式存儲(chǔ)  
          46.     private String star;  
          47.       
          48.     //鏈接地址  
          49.     private String detailaddress;  
          50.       
          51.     //評(píng)論包括:評(píng)論者、評(píng)論時(shí)間、評(píng)論內(nèi)容、評(píng)論星級(jí)  
          52.     private Details details;  
          53.       
          54.     //包名  
          55.     private String packageName;  
          56.       
          57.     //啟動(dòng)程序Class  
          58.     private String className;  
          59.       
          60.     public String getTitle() {  
          61.           
          62.         return title;  
          63.     }  
          64.   
          65.     public void setTitle(String title) {  
          66.           
          67.         this.title = title;  
          68.     }  
          69.   
          70.     public String getVersion() {  
          71.           
          72.         return version;  
          73.     }  
          74.   
          75.     public void setVersion(String version) {  
          76.           
          77.         this.version = version;  
          78.     }  
          79.   
          80.     public String getContent() {  
          81.           
          82.         return content;  
          83.     }  
          84.   
          85.     public void setContent(String content) {  
          86.           
          87.         this.content = content;  
          88.     }  
          89.   
          90.     public String getAuthor() {  
          91.           
          92.         return author;  
          93.     }  
          94.   
          95.     public void setAuthor(String author) {  
          96.           
          97.         this.author = author;  
          98.     }  
          99.   
          100.     public String getIcon() {  
          101.           
          102.         return icon;  
          103.     }  
          104.   
          105.     public void setIcon(String icon) {  
          106.           
          107.         this.icon = icon;  
          108.     }  
          109.   
          110.     public String getPrice() {  
          111.           
          112.         return price;  
          113.     }  
          114.   
          115.     public void setPrice(String price) {  
          116.           
          117.         this.price = price;  
          118.     }  
          119.   
          120.     public String getStar() {  
          121.           
          122.         return star;  
          123.     }  
          124.   
          125.     public void setStar(String star) {  
          126.           
          127.         this.star = star;  
          128.     }  
          129.   
          130.   
          131.     public String getDetailaddress() {  
          132.           
          133.         return detailaddress;  
          134.     }  
          135.   
          136.     public void setDetailaddress(String detailaddress) {  
          137.           
          138.         this.detailaddress = detailaddress;  
          139.     }  
          140.   
          141.     public String[] getDemos() {  
          142.           
          143.         return Demos;  
          144.     }  
          145.   
          146.     public void setDemos(String[] demos) {  
          147.           
          148.         Demos = demos;  
          149.     }  
          150.       
          151.   
          152.     public Details getDetails() {  
          153.           
          154.         return details;  
          155.     }  
          156.   
          157.     public void setDetails(Details details) {  
          158.           
          159.         this.details = details;  
          160.     }  
          161.   
          162.     public String getPackageName() {  
          163.           
          164.         return packageName;  
          165.     }  
          166.   
          167.     public void setPackageName(String packageName) {  
          168.           
          169.         this.packageName = packageName;  
          170.     }  
          171.   
          172.     public Drawable getDicon() {  
          173.           
          174.         return dicon;  
          175.     }  
          176.   
          177.     public void setDicon(Drawable dicon) {  
          178.           
          179.         this.dicon = dicon;  
          180.     }  
          181.   
          182.     public String getLabel() {  
          183.           
          184.         return label;  
          185.     }  
          186.   
          187.     public void setLabel(String label) {  
          188.           
          189.         this.label = label;  
          190.     }  
          191.   
          192.     public String getNewVersion() {  
          193.           
          194.         return newVersion;  
          195.     }  
          196.   
          197.     public void setNewVersion(String newVersion) {  
          198.           
          199.         this.newVersion = newVersion;  
          200.     }  
          201.   
          202.     public String getClassName() {  
          203.           
          204.         return className;  
          205.     }  
          206.   
          207.     public void setClassName(String className) {  
          208.           
          209.         this.className = className;  
          210.     }  
          211.   
          212.       
          213.   
          214.       
          215. }  

           

          自定義:AppParcelable

          Java代碼 
          1. import android.os.Parcel;  
          2. import android.os.Parcelable;  
          3.   
          4. import com.tcad.marketassistant.vo.MyApplicationInfo;  
          5.   
          6. public class AppParcelable implements Parcelable {  
          7.   
          8.     private MyApplicationInfo info;  
          9.       
          10.     public AppParcelable(Parcel source){  
          11.           
          12.         info = (MyApplicationInfo)source.readValue(MyApplicationInfo.class.getClassLoader());  
          13.               
          14.     }  
          15.       
          16.     public AppParcelable(MyApplicationInfo info){  
          17.           
          18.         this.info = info;  
          19.     }  
          20.       
          21.     public int describeContents() {  
          22.           
          23.         return 0;  
          24.     }  
          25.   
          26.     public void writeToParcel(Parcel dest, int flags) {  
          27.           
          28.         dest.writeValue(info);  
          29.     }  
          30.   
          31.   
          32.     public static final Parcelable.Creator<AppParcelable> CREATOR = new Parcelable.Creator<AppParcelable>() {  
          33.   
          34.         public AppParcelable createFromParcel(Parcel source) {  
          35.               
          36.             return new AppParcelable(source);  
          37.         }  
          38.   
          39.         public AppParcelable[] newArray(int size) {  
          40.               
          41.         //  return new AppParcelable[size];  
          42.             throw new UnsupportedOperationException();   
          43.         }  
          44.           
          45.     };  
          46.       
          47.     public MyApplicationInfo getInfo(){  
          48.           
          49.         return info;  
          50.     }  
          51. }  

           調(diào)用代碼,發(fā)送:

          Java代碼 
          1. AppParcelable parcelable = new AppParcelable(info);  
          2. //Info為MyApplicationInfo對(duì)象            
          3.             // 發(fā)送對(duì)象  
          4.             intent.putExtra("app_parcelable", parcelable);  
          5.               
          6.             startActivity(intent);  

           接收:

          Java代碼 
          1. AppParcelable p = getIntent().getParcelableExtra("app_parcelable");  
          2.               
          3.             MyApplicationInfo info = p.getInfo();  

           

          posted on 2010-09-10 16:00 九寶 閱讀(2138) 評(píng)論(0)  編輯  收藏 所屬分類: android

          主站蜘蛛池模板: 大方县| 台山市| 永兴县| 泰来县| 凭祥市| 石泉县| 德化县| 玉山县| 稻城县| 清丰县| 金川县| 宁都县| 惠东县| 沅江市| 靖安县| 西林县| 新田县| 安西县| 达拉特旗| 宣化县| 略阳县| 浦北县| 伊金霍洛旗| 德兴市| 德令哈市| 瑞丽市| 石台县| 榆中县| 左云县| 隆安县| 赤水市| 嘉义市| 诏安县| 河津市| 龙口市| 肇源县| 泗阳县| 盱眙县| 通州市| 石门县| 辽源市|