【发布时间】:2014-11-06 12:31:15
【问题描述】:
在我的应用程序的一个活动中,我有一个启动新活动的意图,我想传递一个 ArrayList,即一个 ArrayList,其中每个项目都是一个自己的类的实例......我该怎么做?
我已经看到了可能的 getExtras(),例如 getStringArrayList() 或 getParcelableArrayList(),但它不起作用,我没有找到任何有效的类型。
谁能帮帮我?谢谢。
这是我的课:
public class ItemFile {
protected long id;
protected String nombre;
protected String rutaImagen;
protected boolean checked;
public ItemFile(long id, String nombre, String rutaImagen, boolean check) {
this.id = id;
this.nombre = nombre;
this.rutaImagen = rutaImagen;
this.checked = check;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getNombre() {
return nombre;
}
public void setNombre(String nombre) {
this.nombre = nombre;
}
public String getRutaImagen() {
return rutaImagen;
}
public void setRutaImagen(String rutaImagen) {
this.rutaImagen = rutaImagen;
}
public boolean isChecked() {
return checked;
}
public void setChecked(boolean checked){
this.checked = checked;
}
}
我必须如何更改它以设置 Parcelable?
【问题讨论】:
-
您可以尝试使用 Parcable 实现 MyClass。看看这里。 stackoverflow.com/a/7181792/1602333
-
这是最好的答案。在这篇文章中,它解释了我的问题。这篇文章的最后一个答案非常有用。
标签: android android-intent arraylist