我想在我的應用程序中將Team
類型的對象傳遞給另一個Activity
。如何使用parcelable將對象從一個Android活動發送到另一個活動?
的Team
類:
TreeMap<String, HashMap<Integer, ArrayList<Event>>> matchDays;
如何傳遞嵌套TreeMap中與班上其他同學一起:
public class Team implements Parcelable {
String teamName;
//Name and Link to competition of Team
TreeMap<String, String> competitions;
//Name of competition with a map of matchdays with all games to a matchday
TreeMap<String, HashMap<Integer, ArrayList<Event>>> matchDays;
public int describeContents() {
return 0;
}
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(teamName);
dest.writeMap(competitions);
}
public static final Parcelable.Creator<Team> CREATOR = new Parcelable.Creator<Team>() {
public Team createFromParcel(Parcel in) {
return new Team(in);
}
public Team[] newArray(int size) {
return new Team[size];
}
};
private Team(Parcel in) {
teamName = in.readString();
in.readMap(competitions, Team.class.getClassLoader());
}
}
我編組時收到一個RuntimeException?
什麼是事件? Event類是可序列化的嗎? – kosa 2012-07-06 20:23:10