Closed P1NG2WIN closed 4 years ago
Yes that shouldn't be a problem, use kotlin-android-extensions
, but afaik it's still experimental.
Yes that shouldn't be a problem, use
kotlin-android-extensions
, but afaik it's still experimental.
As far as I know, the view holder must be configured to work with synthetic, out of the box it does not work and each time use findViewById if we use itemView.'...'
Hmm well thats all taken care of with the org.jetbrains.kotlin.android.extensions
that is auto generating these properties for all the different view controller types (Activity, Fragment, Dialog etc)
Important is to use RecyclerView.ViewHolder.itemView
as the root view for the synthetic property resolving.
Pattern for synthetic property import is:
import kotlinx.android.synthetic.<variantName>.<layoutName>.view.<viewName>
Try out this:
apply plugin: 'org.jetbrains.kotlin.android.extensions'
androidExtensions {
experimental = true
}
import kotlinx.android.synthetic.main.layoutName.view.title
class TitleViewHolder(parentView: ViewGroup) :
SmartViewHolder<Model>(parentView, R.id.layoutName) {
override fun bind(item: Model) {
itemView.title.text = item.title
}
}
I've included some synthetic imports in the sample app so i'm closing this issue for now :)
Does this library support Kotlin synthetics or view binding in ViewHolder?