2011-04-12 91 views
1

编辑:我已经更新了我的问题相当多,现在与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>为什么呢?

+1

本教程应该可以帮助您实现parcelable接口:http://www.anddev.org/simple_tutorial_passing_arraylist_across_activities-t9996.html – 2bard 2011-04-12 14:39:28

回答

1

类似的问题已被要求here。希望它可以帮助你!

0

您可以使用SQLite作为替代。将数据从一个活动传递到另一个活动。这里link

+0

什么表现像这个? – Skizit 2011-04-12 14:44:51

1

你能使用来自bundle.putSerializable()所有字符串值,然后切换到bundle.putStringArrayList("key", ArrayList<String>_object)

相关问题