我認爲這只是一個愚蠢的錯誤,但ArrayList
總是結束null
。這讓我瘋狂,所以我想請求幫助。ArrayList的自定義實現<custom-object>
對象類:
import android.os.Parcel;
import android.os.Parcelable;
public class StoryTag implements Parcelable {
private String tagTitle;
private int occurrence;
public StoryTag() {
}
public StoryTag(Parcel in) {
tagTitle = in.readString();
occurrence = in.readInt();
}
public String getTagTitle() {
return tagTitle;
}
public void setTagTitle(String tagstring) {
this.tagTitle = tagstring;
}
public int getOccurrence() {
return occurrence;
}
public void setOccurrence(int occurrence) {
this.occurrence = occurrence;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(tagTitle);
dest.writeInt(occurrence);
}
public int describeContents() {
return 0;
}
public static final Parcelable.Creator<StoryTag> CREATOR = new Parcelable.Creator<StoryTag>() {
public StoryTag createFromParcel(Parcel in) {
return new StoryTag(in);
}
public StoryTag[] newArray(int size) {
return new StoryTag[size];
}
};
}
MainActivity
:
Intent tagIntent=new Intent(this,DisplayTagList.class);
tagIntent.putExtra("taglist", taglist);
startActivity(tagIntent);
return true;
接收活動:
Bundle storyTagBundle = getIntent().getExtras();
ArrayList<StoryTag> listoftags = storyTagBundle.getParcelable("taglist");
感謝一噸,你可以提供任何幫助。把我的頭髮拉出來,因爲我認爲這是一個小錯誤。
請關注此:http://andhradroid.wordpress.com/2012/04/02/how-to-pass-the-object-one-activity-from-another/ – 2013-02-21 04:42:12