zoukankan      html  css  js  c++  java
  • android 开发Parcelable 怎么传值ArrayList

    public class TradeEntity implements Parcelable{
        public String id;
        
        //有关进度条的参数
        ArrayList<TradeStateNodeInfo> nodes;
        public TradeEntity() {
            nodes = new ArrayList<TradeStateNodeInfo>();
        }
        /////////////////////////实现parcel接口///////////////////////////////
        @Override
        public int describeContents() {
            return 0;
        }
        @Override
        public void writeToParcel(Parcel out, int arg1) {
            out.writeString(id);
            out.writeList(nodes);
        }
        private TradeEntity(Parcel in)
        {
            id = in.readString();
            nodes = in.readArrayList(TradeStateNodeInfo.class.getClassLoader());
        }
        public static final Parcelable.Creator<TradeEntity> CREATOR = new Parcelable.Creator<TradeEntity>() 
        {
            public TradeEntity createFromParcel(Parcel in) 
            {
                return new TradeEntity(in);
            }
    
            public TradeEntity[] newArray(int size) 
            {
                return new TradeEntity[size];
            }
        };
    }

     以上问题还会出现不能传值的问题,解决如下:

    将 TradeStateNodeInfo 也要实现parcel接口

    import android.os.Parcel;
    import android.os.Parcelable;
    
    /**
     * 交易状态
     * @author huqiang
     *
     */
    public class TradeStateNodeInfo implements Parcelable{
    
        public int active;   //颜色激活(-1、错误;0、未激活;1、激活;2、当前步骤成功)
        public String time ; 
        public String name ; //节点名称
        
        public TradeStateNodeInfo()
        {}
        private TradeStateNodeInfo(Parcel in)
        {
            active = in.readInt();
            time = in.readString();
            name = in.readString();
        }
        @Override
        public int describeContents() {
            return 0;
        }
        @Override
        public void writeToParcel(Parcel out, int flag) {
            out.writeInt(active);
            out.writeString(time);
            out.writeString(name);
        }
        public static final Parcelable.Creator<TradeStateNodeInfo> CREATOR = new Parcelable.Creator<TradeStateNodeInfo>() 
        {
            public TradeStateNodeInfo createFromParcel(Parcel in) 
            {
                return new TradeStateNodeInfo(in);
            }
    
            public TradeStateNodeInfo[] newArray(int size) 
            {
                return new TradeStateNodeInfo[size];
            }
        };
    }
  • 相关阅读:
    Git-Runoob:Git 查看提交历史
    Git-Runoob:Git 分支管理
    Git-Runoob:Git 基本操作
    Git-Runoob:Git 创建仓库
    weblogic11g 安装集群 —— win2003 系统、单台主机
    关于条件宏的易错点
    关于端口号你知道多少!
    POJ 2114 Boatherds【Tree,点分治】
    Android应用开发学习笔记之Intent
    对于接收到的GPS信息详解
  • 原文地址:https://www.cnblogs.com/feijian/p/4776394.html
Copyright © 2011-2022 走看看