Skip to content

Latest commit

 

History

History
27 lines (21 loc) · 965 Bytes

File metadata and controls

27 lines (21 loc) · 965 Bytes

Kotlin Extension for Core Adapter

According to article
if you want to work with DynamicAdapter and keep performance of ViewHolder bind your ListItems in next way:

import com.nullgr.core.adapter.ktx.AdapterDelegate
import com.nullgr.core.adapter.ktx.ViewHolder

import kotlinx.android.synthetic.main.item_some.*

class SomeDelegate : AdapterDelegate() {

    override val layoutResource: Int = R.layout.item_some
    override val itemType: Any = SomeItem::class
    
    override fun onBindViewHolder(items: List<ListItem>, position: Int, holder: RecyclerView.ViewHolder) {
        val item = items[position] as SomeItem

        with(holder as ViewHolder) {
            titleView.text = item.title
            subTitleView.text = item.subTitle
            colorView.setBackgroundColor(item.color)
        }
    }
}