1

私の最後の質問の続きとして:アクティビティ間でArraylistを渡す?パーセラブルの使用

現在、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;
  }
 }

listOfResultsとして宣言されResultsList listOfResults = new ResultsList();、コードの前半で入力されます。その後、..で送信されます。

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

受信中...

    Bundle extras = getIntent().getExtras();
    ResultsList results = extras.getParcelable("results");

バンドルに入るArraylistのsize()をチェックしてから出てくることで、このnullをテストしていることを指摘したいと思います。それはうまくいき、ヌルになります。

4

1 に答える 1

0

バンドルをインテントに添付しませんでした!(doh!)IRCの親切な紳士から指摘されました!#android-dev

于 2011-04-13T09:30:23.153 に答える