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());
    }
    }
  • 相关阅读:
    c++ heap学习
    超长正整数相加
    Search Insert Position
    strcpy与strcat函数原型
    C++基本数据类型占字节数
    详解指针的指针
    Google 超分辨率技术 RAISR
    elementui resetFields方法重置表单失败
    VS 点击文件自动定位到解决方案资源管理器中文件所在目录位置
    mybatis中LIKE模糊查询的几种写法以及注意点
  • 原文地址:https://www.cnblogs.com/lenkevin/p/5802224.html
Copyright © 2011-2022 走看看