0
如何在两个活动之间传递和获取“myobject1”?android意图 - 传递数据
第一项活动:
private ArrayList<Custom> myobject1 = new ArrayList<Custom>();
...
i.putExtra("myobject1", myobject1);
次活动:
results =(ArrayList<Custom>) getIntent().getSerializableExtra("myobject1");
这里是我的Custom.class:
public class Custom implements Comparable<Custom>{
private String big;
private String small;
public Custom(String n,String d)
{
big = n;
small = d;
}
public String getFirst()
{
return big;
}
public String getSecond()
{
return small;
}
@Override
public int compareTo(Custom o) {
if(this.big != null)
return this.big.toLowerCase().compareTo(o.getFirst().toLowerCase());
else
throw new IllegalArgumentException();
}
}
这时我发现了错误: ê/AndroidRuntime(8032):java.lang.RuntimeException:包裹:无法编组值
我觉得自定义需要可序列化 – poitroae 2011-12-18 11:57:49
怎么做? – Dikobraz 2011-12-18 11:59:02
@Dikobraz为了使其可串行化,只需实现'Customizable'类的'Serializable'接口。 – Roshnal 2011-12-18 12:54:30