适配器更新时 CardStackLayoutManager 重新启动

问题描述

我正在使用 CardStackLayoutManager 实现一个列表。我的问题是,当我到达列表的最后一项时,我调用一个方法获取其他元素,但是当我更新适配器(使用 update() 函数)时,列表从第一个位置开始,而不是从我已经到达的那个。 Adapter 本身应该没有问题,因为我使用与基本 RecyclerView 相同的逻辑并且我没有这个问题,所以我不知道我是否必须更改某些内容以使其适应 CardStackLayoutManager。

CardStackLayoutManager 库:https://github.com/yuyakaido/CardStackView

这是适配器:

class Adapter(private val items: MutableList<EstimationModel>) :
        RecyclerView.Adapter<Adapter.ViewHolder>() {

        fun update(list: MutableList<EstimationModel>) {
            this.items.addAll(list)
            notifyDataSetChanged()
        }

        fun clearList() = items.clear()

        fun getPage(): Int = (items.size / BuildConfig.PAGE_SIZE)

        override fun onCreateViewHolder(
            parent: ViewGroup,viewType: Int
        ): ViewHolder {
            val view = LayoutInflater.from(parent.context).inflate(R.layout.item_estimation,parent,false)
            return ViewHolder(view)
        }

        override fun onBindViewHolder(holder: ViewHolder,position: Int) {
            holder.bindItem(items[position])
        }

        override fun getItemCount(): Int = items.size

        class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
            fun bindItem(item: EstimationModel) {
                val date = Date(item.lastModifiedDate!!)
                val sdf = SimpleDateFormat("dd MMMM yyyy",Locale.getDefault())

                itemView.item_history_date.text = sdf.format(date)

                itemView.item_history_list.layoutManager = linearlayoutmanager(itemView.context)
                itemView.item_history_list.setHasFixedSize(true)
                itemView.item_history_list.adapter = ItemAdapter(item.estimationCatalogs)
            }
        }
    }

编辑:解决方

我编辑更新了这个功能问题解决了。希望这会帮助某人:

fun update(list: MutableList<EstimationModel>) {
            this.items.addAll(list)
            notifyItemRangeInserted(items.size - list.size,list.size)
        }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...