将新的父对象添加到ExpandableRecyclerAdapter

noo*_*oob 5 generics android android-recyclerview expandablerecyclerview

我在我的项目中使用ExpandableRecyclerView来嵌套RecyclerView.它工作得很好,除非您需要动态更新父列表.

我的项目将Product类作为父对象(并扩展ParentListItem).我从API获取产品列表,因此需要清除当前列表并添加我有的列表.

在ExpandableRecyclerAdapter中我试过这个方法 -

public void onDataChanged(ArrayList<Product> parentObjects) {
    this.getParentItemList().clear();
    this.getParentItemList().addAll(parentObjects);

    this.notifyItemRangeChanged(0, parentObjects.size() - 1);
}
Run Code Online (Sandbox Code Playgroud)

然而,它给出了一个奇怪的通用错误

Error:(60, 33) error: no suitable method found for addAll(ArrayList<Product>)
method List.addAll(Collection<? extends CAP#1>) is not applicable
(actual argument ArrayList<Product> cannot be converted to Collection<? extends CAP#1> by method invocation conversion)
method List.addAll(int,Collection<? extends CAP#1>) is not applicable
(actual and formal argument lists differ in length)
method Collection.addAll(Collection<? extends CAP#1>) is not applicable
(actual argument ArrayList<Product> cannot be converted to Collection<? extends CAP#1> by method invocation conversion)
where CAP#1 is a fresh type-variable:
CAP#1 extends ParentListItem from capture of ? extends ParentListItem
Run Code Online (Sandbox Code Playgroud)

parentItemList是类型的List<? extends ParentListItem>,所以根据这个问题,不可能向现有列表添加任何内容,因为没有setter存在,我也无法替换完整列表.

我尝试创建一个新ExpandableRecyclerAdapter对象并将其设置为RecyclerView的新适配器.虽然它有效,但我不认为这是一个很好的方法来替换整个适配器,无论何时有新数据出现.

那么有没有其他方法可以一次性或逐个更新父对象列表?