1
類我遇到了一個實現Parcelable的類讀取字符串ArrayList的麻煩。使用一個ArrayList <String>與擴展Parcelable
我想發送3個字符串ArrayLists到一個片段。我不明白的另一件事是我如何使用這個類來實際地將這些數據發送到Fragment(我讀過其他地方,你可以使用你自己的parcelable類來做到這一點,但我不知道如何)。
這裏是相關的代碼,我會在我認爲我需要幫助的地方發表評論。
package com.tsjd.HotMeals;
import java.util.ArrayList;
import android.os.Parcel;
import android.os.Parcelable;
public class RecipeListViewParcer implements Parcelable{
private ArrayList<String> titles;
private ArrayList<String> descriptions;
private ArrayList<String> images;
private RecipeListViewParcer(Parcel in) {
titles = in.readArrayList(String.class.getClassLoader()); //Need help here
descriptions = in.readArrayList(String.class.getClassLoader()); //Need help here
images = in.readArrayList(String.class.getClassLoader()); //Need help here
}
public int describeContents() {
return 0;
}
public void writeToParcel(Parcel out, int flags) {
out.writeList(titles); //Need help here
out.writeList(descriptions); //Need help here
out.writeList(images); //Need help here
}
public static final Parcelable.Creator<RecipeListViewParcer> CREATOR
= new Parcelable.Creator<RecipeListViewParcer>() {
public RecipeListViewParcer createFromParcel(Parcel in) {
return new RecipeListViewParcer(in);
}
public RecipeListViewParcer[] newArray(int size) {
return new RecipeListViewParcer[size];
}
};
}