问题描述
我正在使用 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 (将#修改为@)