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());
    }
    }
  • 相关阅读:
    Python IDE
    python 3.x 不再提供raw_print()
    Python代码风格建议(转)
    在JSP页面中输出JSON格式数据
    MyEclipse 10 优化
    MB/GB/TB/PB/EB/ZB/YB/NB/DB/CB存储空间都是多大?如何换算?
    为什么民众不以偷税为耻_岑科
    彻底解剖人民币升值问题_岑科
    script 加载顺序问题的延展研究
    如何快速实现 markdown 转 HTML 文档?
  • 原文地址:https://www.cnblogs.com/lenkevin/p/5802224.html
Copyright © 2011-2022 走看看