「android開発」Parcelable直列化を実現するサンプルコード

Javaコード:
package com.mat.pocketbook.bean;

import android.os.Parcel;
import android.os.Parcelable;
import android.os.Parcelable.Creator;

public class ProductBrandBean_Startnews24 implements Parcelable {
private int id;
private int conunt;
private String urlIcon;
private String brandName;

public static final Parcelable.Creator<ProductBrandBean_Startnews24> CREATOR = new Creator<ProductBrandBean_Startnews24>() {

@Override
public ProductBrandBean_Startnews24 createFromParcel(Parcel source) {
// TODO Auto-generated method stub
// メンバ変数宣言を順次に読み取る
ProductBrandBean_Startnews24 p = new ProductBrandBean_Startnews24();
p.setId(source.readInt());
p.setConunt(source.readInt());
p.setUrlIcon(source.readString());
p.setBrandName(source.readString());
return p;
}

@Override
public ProductBrandBean_Startnews24[] newArray(int size) {
// TODO Auto-generated method stub
return new ProductBrandBean_Startnews24[size];
}
};
public String getBrandName() {
return brandName;
}
public void setBrandName(String brandName) {
this.brandName = brandName;
}
public ProductBrandBean_Startnews24() {
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getConunt() {
return conunt;
}
public void setConunt(int conunt) {
this.conunt = conunt;
}
public String getUrlIcon() {
return urlIcon;
}
public void setUrlIcon(String urlIcon) {
this.urlIcon = urlIcon;
}
@Override
public int describeContents() {
// TODO Auto-generated method stub
return 0;
}

@Override
public void writeToParcel(Parcel dest, int flags) {
// オブジェクトのシリアライゼーション
dest.writeInt(id);
dest.writeInt(conunt);
dest.writeString(urlIcon);
dest.writeString(brandName);

}

}

Java

Posted by arkgame