前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >AS插件-Android Parcelable code generator.

AS插件-Android Parcelable code generator.

作者头像
小小工匠
发布2021-08-16 10:32:25
3020
发布2021-08-16 10:32:25
举报
文章被收录于专栏:小工匠聊架构

概述

生成实现了Parcelable接口的代码的插件

下载安装

1.在线安装

这里写图片描述
这里写图片描述

输入 Android Parcelable code generator ,点击安装即可,安装之后 重启,会看到上图选中部分所示。

2.手动下载安装 https://github.com/mcharmas/android-parcelable-intellij-plugin

使用

在你的类中,按下alt + insert键弹出插入代码的上下文菜单,会看到在下面有一个Parcelable,选择它之后,就会在你的类当中插入实现了Parcelable接口的代码了。

这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述

经验证,勾选Product的3个变量 和不选,生成的代码是一样的。

代码如下(setter+getter是之前已经写好了的)

代码语言:javascript
复制
package com.turing.base.activity.test;

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

/**
 * MyApp
 *
 * @author Mr.Yang on 2016-04-13  22:32.
 * @version 1.0
 * @desc
 */
public class Product implements Parcelable {

    private int id;
    private String name;
    private float price;


    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public float getPrice() {
        return price;
    }

    public void setPrice(float price) {
        this.price = price;
    }


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

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(this.id);
        dest.writeString(this.name);
        dest.writeFloat(this.price);
    }

    public Product() {
    }

    protected Product(Parcel in) {
        this.id = in.readInt();
        this.name = in.readString();
        this.price = in.readFloat();
    }

    public static final Creator CREATOR = new Creator() {
        @Override
        public Product createFromParcel(Parcel source) {
            return new Product(source);
        }

        @Override
        public Product[] newArray(int size) {
            return new Product[size];
        }
    };
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2016/04/13 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 概述
  • 下载安装
  • 使用
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档