Android使用包

时间:2016-07-28 23:02:29

标签: android

这是我的数组列表:

 private List<myclass> arrList = new ArrayList<myclass>();

我的代码:

public class myclass implements Serializable {

private int user_id;
private String fname;
private String EditVal;

public myclass() {

}

public myclass(String fname, int user_id, String EditVal) {  
    this.user_id = user_id;
    this.fname = fname;
    this.EditVal = EditVal;
}


public String getFname(){
    return fname;
}

public String EditVal(){
    return EditVal;
}

}

现在在活动中我想将项目添加到数组列表并使用包

传递它
    Bundle outState = new Bundle ();

    myclass r = new myclass("medo medo",40, TxtVal);
    arrList.add(r);
    outState.putSerializable("savedList",  arrList);

但它给我和错误

  

java.lang.RuntimeException:Parcelable遇到编写可序列化对象的IOException

     

引起:java.io.NotSerializableException

1 个答案:

答案 0 :(得分:0)

如果它实现 Serializable Parcelable ,您可以传递自己类的ArrayList。
这是因为它被序列化并“压缩”到捆绑中。

Bundle outState = new Bundle ();

myclass r = new myclass("medo medo",40, TxtVal);
arrList.add(r);
// outState.putSerializable("savedList",  arrList);
outState.putParcelableArrayList("savedList", arraylist);

此致