RecyclerView wrong position set onBindViewHolder

前端 未结 4 1298
误落风尘
误落风尘 2021-02-18 13:30

At First, my RecyclerView items are ok, but on scrolling, items are shown on the wrong position for example: item 6 shown in position 67. Although onClick listener and getAdapte

4条回答
  •  借酒劲吻你
    2021-02-18 13:59

    None of the methods above worked in every situation for me and I don't want to sacrifice the recyclability. The only working solution that I found is to modify the return for both of these methods inside the adapter to "position" values:

    override fun getItemViewType(position: Int): Int {
            return position
    }
    
    override fun getItemId(position: Int): Long {
           return position.toLong()
    }
    

    The returned position will be always correct. It needs to be modified if you are using viewType.

提交回复
热议问题