Android Studio中Android Parcelable code generator插件的使用

public class JuheTimeNews extends BaseResponse implements Parcelable {
    public float[] result;
    public String[] names;
    public List<Float> prices;
    public List<String> numbers;

    public JuheTimeNews() {
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeFloatArray(this.result);
        dest.writeStringArray(this.names);
        dest.writeList(this.prices);
        dest.writeList(this.numbers);
        dest.writeInt(this.resultcode);
        dest.writeString(this.reason);
        dest.writeInt(this.error_code);
    }

    private JuheTimeNews(Parcel in) {
        this.result = in.createFloatArray();
        this.names = in.createStringArray();
        this.prices = new ArrayList<Float>();
        in.readList(this.prices, Float.class.getClassLoader());
        this.numbers = new ArrayList<String>();
        in.readList(this.numbers, String.class.getClassLoader());
        this.resultcode = in.readInt();
        this.reason = in.readString();
        this.error_code = in.readInt();
    }

    public static final Creator<JuheTimeNews> CREATOR = new Creator<JuheTimeNews>() {
        public JuheTimeNews createFromParcel(Parcel source) {
            return new JuheTimeNews(source);
        }

        public JuheTimeNews[] newArray(int size) {
            return new JuheTimeNews[size];
        }
    };
}

此插件对于各种类型,如float[]数组类型,List<Student>类型的支持都很好。

但是对于List<String>、List<Float>等类型支持的不是很好,需要手动的修改一下即可。


      this.prices = new ArrayList<<span style="color:#ff6666;">List<Float></span>>();
        in.readList(this.prices, <span style="color:#ff6666;">List<Float></span>.class.getClassLoader()); // 红色部分的List<Float>整个替换成为Float就可以了。
        this.numbers = new ArrayList<span style="color:#3366ff;"><List<String></span>>();
        in.readList(this.numbers, <span style="color:#3366ff;">List<String></span>.class.getClassLoader()); <span style="font-family: Arial, Helvetica, sans-serif;">//蓝色部分的 List<String>整个替换成为String就可以了。</span>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值