zoukankan      html  css  js  c++  java
  • Gson解析复杂的Bean类实现Parcelable

    import java.util.ArrayList;
    import android.os.Parcel;
    import android.os.Parcelable;
    import android.support.v4.os.ParcelableCompat;
    
    public class Question implements Parcelable{
    
    
    String id;
    String text;
    String image;
    ArrayList<Choices> CHOICES;
    
    
    public Question(String id, String text, String image) {
        super();
        this.id = id;
        this.text = text;
        this.image = image;
    }
    
    public String getId() {
        return id;
    }
    
    public void setId(String id) {
        this.id = id;
    }
    
    public String getText() {
        return text;
    }
    
    public void setText(String text) {
        this.text = text;
    }
    
    public String getImage() {
        return image;
    }
    
    public void setImage(String image) {
        this.image = image;
    }
    
    @Override
    public String toString() {
        return "Question [id=" + id + ", text=" + text + ", image=" + image
                + "]";
    }
    
    
    
    
    // Answer Choices class
    class Choices {
    
        boolean isCorrect;
        String choice;
    
        public Choices(boolean isCorrect, String choice) {
            this.isCorrect = isCorrect;
            this.choice = choice;
        }
    
        public String getChoice() {
            return choice;
        }
    
        public boolean getIsCorrect() {
            return isCorrect;
        }
    
        @Override
        public String toString() {
            return "Choices [isCorrect=" + isCorrect + ", choice=" + choice
                    + "]";
        }
    
    }
    
    
    public static final Parcelable.Creator<Question> CREATOR = new Parcelable.Creator<Question>() {
    
        @Override
        public Question createFromParcel(Parcel in) {
            return new Question(in);
        }
    
        @Override
        public Question[] newArray(int size) {
            return new Question[size];
        }
    
    };
    
    @Override
    public int describeContents() {
        // TODO Auto-generated method stub
        return 0;
    }
    
    @Override
    public void writeToParcel(Parcel dest, int flags) {
    
        dest.writeString(id);
        dest.writeString(text);
        dest.writeString(image);
        dest.writeList(CHOICES);
    
    }
    
    private Question(Parcel in) {
        this.id = in.readString();this.text =in.readString();this.image =in.readString();this.CHOICES =in.readArrayList(Choices.class.getClassLoader());
    }
    }
  • 相关阅读:
    配置JAVA的环境变量
    Navicat Premium v12.0.23.0 安装,使用激活码激活
    mysql 5.7.33安装教程
    查看mysql服务
    postman测试post请求参数是List entity后端用@RequestBody接受lIst entity方式
    最简单的MySQL安装教程(数据库免安装版,免安装版,亲测好用) mysql-5.7.33-winx64.zip
    mysql数据库安装5.7.33
    java删除附件图片
    java生成条形码
    最高的牛
  • 原文地址:https://www.cnblogs.com/lenkevin/p/5802224.html
Copyright © 2011-2022 走看看