Android 通过意图将包含对象的对象传递给活动
我有一个对象需要通过Intent通过onclick方法传递给另一个活动 我在这里遵循这个答案 这很好,但是我的对象中有一个对象数组 如何传递此对象及其对象数组 以下是使用Parcelable之前的课程 列表(要传递的对象) 那么我如何使用列表上的Parcelable发送ArrayList呢Android 通过意图将包含对象的对象传递给活动,android,android-intent,parcelable,Android,Android Intent,Parcelable,我有一个对象需要通过Intent通过onclick方法传递给另一个活动 我在这里遵循这个答案 这很好,但是我的对象中有一个对象数组 如何传递此对象及其对象数组 以下是使用Parcelable之前的课程 列表(要传递的对象) 那么我如何使用列表上的Parcelable发送ArrayList呢 谢谢你,如果你需要更多的信息,请询问 您试图传递通常不应该传递的数据。列表是SQLite数据库的理想候选对象。尝试以下方法在android中保存数据: 如果您坚持使用Parcelable: 也不要将列表用作
谢谢你,如果你需要更多的信息,请询问 您试图传递通常不应该传递的数据。列表是SQLite数据库的理想候选对象。尝试以下方法在android中保存数据: 如果您坚持使用Parcelable:
也不要将列表用作自己的类型,它是标准JAVA。您不应该将列表用作自己的类型。这是一个java标准的库接口。如果你在谷歌上搜索它,会有成千上万的答案。这里有一条:@VM好点应该改名,也找不到任何自己包的自定义数组列表objects@Raghunandan是的,我已经看过了,但是他在object中只有普通的数据类型。关于使用SQL,这一点很好。我将研究如何使用它。谢谢
public class List {
private String Name;
private ArrayList<ListItem> items;
public List(){
items = new ArrayList<ListItem>();
}
public void addItem(String title, String d, String s, int p){
ListItem i = new ListItem();
i.setDecription(d);
i.setPrice(p);
i.setSite(s);
i.setTitle(title);
items.add(i);
}
public String getName() {
return Name;
}
public void setName(String Name) {
this.Name = Name;
}
public int getCount() {
return items.size();
}
public ArrayList<ListItem> getList(){
return items;
}
}
public class ListItem {
private String title;
private String decription;
private String site;
private int price;
public void setTitle(String title) {
this.title = title;
}
public void setDecription(String d){
this.decription = d;
}
public void setSite(String s){
this.site = s;
}
public void setPrice(int i){
this.price = i;
}
public String getTitle(){
return title;
}
public String getDecription(){
return decription;
}
public String getSite(){
return site;
}
public int getPrice(){
return price;
}
}