【发布时间】:2018-02-11 16:29:11
【问题描述】:
我需要使用 Bundle 将类对象的 ArrayList 传递给另一个片段。
我已经从 post. 尝试过这样的事情
List< SubCateogory > subCatList = allLists.getResult().getCategory().get(position).getSubCategories();
Bundle bundle = new Bundle();
bundle.putParcelableArray(ApplicationVariables.SUB_CAT_LISTS, subCatList);
它显示以下错误。 Wrong 2nd argument type. Found: 'java.util.List<com.healthcamp.healthapp.models.HomeCategory.SubCateogory>', required: 'android.os.Parcelable[]'
My Category、SubCategory 类实现 Parceable 以及 parceable 所需的方法。
Result.java
public class Results implements Parcelable {
@SerializedName("category")
@Expose
private List<Category> category = null;
public List<Category> getCategory() {
return category;
}
public void setCategory(List<Category> category) {
this.category = category;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
}
}
Category.java
public class Category implements Parcelable { ...
SubCategory.java
public class SubCateogory implements Parcelable {...
请提出建议。谢谢。
【问题讨论】:
-
请勿发布代码截图,请将代码复制/粘贴到您的帖子中。
-
你明白
required: 'android.os.Parcelable[]的意思了吗?它需要Parcelable对象的array,而不是列表。 -
@JimGarrison 好的。我删除了屏幕截图。是的,正如@hacksy 所建议的那样,使用了
putParcelableArrayList,它可以工作。
标签: java android android-fragments arraylist bundle