当前位置:  开发笔记 > 编程语言 > 正文

将新的父对象添加到ExpandableRecyclerAdapter

如何解决《将新的父对象添加到ExpandableRecyclerAdapter》经验,为你挑选了0个好方法。

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

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

在ExpandableRecyclerAdapter中我试过这个方法 -

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

    this.notifyItemRangeChanged(0, parentObjects.size() - 1);
}

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

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

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

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

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

推荐阅读
郑小蒜9299_941611_G
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有