传递活动之间的ArrayList?使用Parcelable [英] Passing Arraylist between activities? Using Parcelable
问题描述
编辑:我已经大大更新了我的问题,我现在用Parcelable去为我的方法
I've updated my question considerably and am now going with Parcelable as my method.
我试图传球一个ArrayList从一个活动到另一个。我一直在阅读四周,似乎无法找到我的问题的任何答案。
I'm attempting to a pass an ArrayList from one activity to another. I've been reading around and can't seem to find any answers to my problem.
我有一个的ArrayList< SearchList>
其中实现Parcelable
SearchList具有以下code。 ..
I've got an ArrayList<SearchList>
which implements Parcelable
SearchList has the following code...
public class SearchList implements Parcelable {
private String title;
private String description;
private String link;
public SearchList(String name, String phone, String mail) {
super();
this.title = name;
this.description = phone;
this.link = mail;
}
public SearchList(Parcel source){
/*
* Reconstruct from the Parcel
*/
title = source.readString();
description = source.readString();
link = source.readString();
}
public String gettitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getLink() {
return link;
}
public void setLink(String link) {
this.link = link;
}
public int describeContents() {
// TODO Auto-generated method stub
return 0;
}
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(title);
dest.writeString(description);
dest.writeString(link);
}
public static final Creator<SearchList> CREATOR = new Creator<SearchList>() {
public SearchList createFromParcel(Parcel source) {
return new SearchList(source);
}
public SearchList[] newArray(int size) {
return new SearchList[size];
}
};
}
然而,当我尝试做...
However, when I try and do...
List<SearchList> listOfResults = new ArrayList<SearchList>();
intent.putParcelableArrayListExtra("results", listOfResults);
我得到不适用于类型(字符串,列表与LT; SearchList&GT;
为什么
推荐答案
一个类似的问题已经被问<一个href=\"http://stackoverflow.com/questions/5566921/androidpassing-a-hash-map-between-activities/\">here.希望它可以帮助你!
A similar question has been asked here. Hopefully it can help you!
这篇关于传递活动之间的ArrayList?使用Parcelable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!