答案 0 :(得分:2)
您可以创建一个更方便的onBind
扩展功能,其中item
,view
等传递给lambda而不是接收ItemViewTypePosition
:
inline fun LastAdapter.Builder.onBind(crossinline f: (item: Any, view: View, type: Int, position: Int) -> Unit): LastAdapter.Builder {
return onBindListener(object : OnBindListener {
override fun onBind(item: Any, view: View, type: Int, position: Int) {
f(item, view, type, position)
}
})
}
用法:
builder.onBind { item, view, type, position ->
when (item) {
is Product -> view.number_sold.text = item.price.toString()
}
}
答案 1 :(得分:1)
答案 2 :(得分:0)
另一种方法是自己制作演员:
.onBind {
when(item) {
is Product -> view.number_sold_text = (item as Product).price.toString()
}
}