首页 > 解决方案 > Kotlin如何枚举recyclerView中的每一行

问题描述

我正在使用 Kotlin,在 recyclerView 中我需要枚举每个加载的单元格(1、2、3 等)。我可以在 IOS 中通过在 cellForRowAt 下添加以下内容来做到这一点:

cell!.cellCount.text = "\(indexPath.row + 1)"

我还没有找到 Kotlin 的等价物,有什么建议吗?先感谢您。

标签: androidkotlinandroid-recyclerview

解决方案


我已经用以下内容更新了我的代码。

内视图Holder

var cellCount = itemView.findViewById<TextView>(R.id.cellCountLbl)

onBindViewHolder 里面

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
    val indexRow = position + 1 
        holder.cellCount.text = indexRow.toString()
        holder.bindPatList(youArray[position])
}

一切都按预期工作。谢谢


推荐阅读