2011-04-12 10 views
1

다음 마지막 질문부터 계속 : Passing Arraylist between activities? Using ParcelableAndroid : getParcelable이 null을 반환합니까?

이제 Parcelable을 통해 ArrayList를 전달하려고합니다. 그러나 다른 활동에서 가져온 경우 null을 반환합니다. 나는 이유를 알 수없는 것 같습니다. 나는 다음과 같은 ...

ResultsList.java에게

public class ResultsList extends ArrayList<SearchList> implements Parcelable { 

    /** 
* 
*/ 
private static final long serialVersionUID = -78190146280643L; 

public ResultsList(){ 

} 

public ResultsList(Parcel in){ 
    readFromParcel(in); 
} 

@SuppressWarnings({ "rawtypes" }) 
public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { 
    public ResultsList createFromParcel(Parcel in) { 
     return new ResultsList(in); 
    } 

    public Object[] newArray(int arg0) { 
     return null; 
    } 

}; 

private void readFromParcel(Parcel in) { 
    this.clear(); 

    //First we have to read the list size 
    int size = in.readInt(); 

    //Reading remember that we wrote first the Name and later the Phone Number. 
    //Order is fundamental 

    for (int i = 0; i < size; i++) { 
     String title = in.readString(); 
     String Des = in.readString(); 
     String message = in.readString(); 
     SearchList c = new SearchList(title,Des,link); 
     this.add(c); 
    } 

} 

public int describeContents() { 
    return 0; 
} 

public void writeToParcel(Parcel dest, int flags) { 
    int size = this.size(); 
    //We have to write the list size, we need him recreating the list 
    dest.writeInt(size); 
    //We decided arbitrarily to write first the Name and later the Phone Number. 
    for (int i = 0; i < size; i++) { 
     SearchList c = this.get(i); 
     dest.writeString(c.gettitle()); 
     dest.writeString(c.getDescription()); 
     dest.writeString(c.getmessage()); 
    } 
} 
} 

SearchList.java

public class SearchList { 
private String title; 
    private String description; 
    private String message; 
    public SearchList(String name, String phone, String mail) { 
      super(); 
      this.title = name; 
      this.description = phone; 
      this.message = mail; 
    } 
    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 getmessage() { 
      return message; 
    } 
    public void setmessage(String link) { 
      this.message = message; 
    } 
} 

listOfResultsResultsList listOfResults = new ResultsList();로 선언 이전 그런 다음에 보낸 것 코드에 가득 차있어 ..

Intent intent = new Intent(this ,newthing.class); 
    Bundle b = new Bundle(); 
    b.putParcelable("results", listOfResults); 
    startActivityForResult(intent,0); 

수신 중 ...

저는 Arraylist의 크기를 확인하여이 null 물건을 테스트하고 있습니다. 그것은 괜찮아지고 null이 나온다.

답변

0

의도에 번들을 부착하지 않았나요! (doh!)는 IRC의 친절한 신사에 의해 지적되었습니다! # android-dev

관련 문제