https://kotlinlang.org logo
#android
Title
# android
l

leosan

11/28/2018, 11:12 PM
Hi I have something like this where my RecyclerViewHolder delegates the creation of the layout to this adapter, is there a way where I can use
LayoutContainer
here in order get cached synthetic views? I Can't find a way to work 😕 LayoutContainer requires the
containerView
initialized at the class initialization but there's no way I can get it on the delegate initialization, only on the
bindView
Copy code
class HeadlineDelegateAdapter @Inject constructor() : BaseDelegateAdapter {

    override fun getLayoutRes(): Int = R.layout.item_dashboard_transaction_headline
    override fun bindView(itemView: View, item: BaseViewType, viewHolder: RecyclerView.ViewHolder) {
        if (item is Headline) {
            tvHeadline.text = item.description
            tvSubtotal.text = item.subtotal
        }
    }
}
@kenkyee Even though I think the subject belongs to this is slack since its about Kotlin Synthetics not being aware of classes that extends classes implementing LayoutContainer I've created a question on SO https://stackoverflow.com/questions/53538375/how-to-make-use-of-kotlin-synthetics-layoutcontainer-on-a-class-that-extends-vie But if this question about kotlin-android-extensions behavior not acting like I was expecting/understood doesn't belong to this slack or kotlin-android channel I don't know actually what really can be discussed here.
k

kenkyee

11/29/2018, 12:07 PM
Kotlixx synth views don't work that great in recycler views IIRC. I think that's what you're hitting. I've seen quirky behavior with them when uses in callbacks too so I don't recommend using them.
l

leosan

11/29/2018, 12:11 PM
databinding then?
k

kenkyee

11/29/2018, 2:00 PM
Yep but even that's a pain in viewholders. There are usually so few views in a viewholder that I just do findviewbyid.