編輯:我已經更新了我的問題相當多,現在與Parcelable作爲我的方法。在活動之間傳遞Arraylist?使用Parcelable
我正試圖從一個活動傳遞一個ArrayList到另一個活動。我一直在閱讀,似乎無法找到我的問題的任何答案。
我有一個ArrayList<SearchList>
其implements Parcelable
SearchList具有下面的代碼...
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];
}
};
}
然而,當我嘗試做...
List<SearchList> listOfResults = new ArrayList<SearchList>();
intent.putParcelableArrayListExtra("results", listOfResults);
我得到not applicable for type (String, List<SearchList>
爲什麼呢?
本教程應該可以幫助您實現parcelable接口:http://www.anddev.org/simple_tutorial_passing_arraylist_across_activities-t9996.html – 2bard 2011-04-12 14:39:28