https://kotlinlang.org logo
s

san

12/03/2020, 3:59 AM
could any one tell how to implement view binding in recycler view adapter class
google 1
stackoverflow 1
u

Umar Ata

12/03/2020, 7:33 AM
Yes
Just use layout in onCreateaViewHolder as you do generally And do not declare any view in your inner class ViewHolder Access view by ViewHolder.itemView.textViewID
s

san

12/03/2020, 7:34 AM
wait i will send my code
j

John Codeos

12/03/2020, 8:22 PM
Hey, I recently made a tutorial on my blog about View Binding, including on how to implement it in RecyclerView Adapter: https://johnc.co/viewbindingandroidtut
s

san

12/25/2020, 8:37 AM
👍
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { val itemViewHolder = holder as ItemViewHolder itemViewHolder.viewBinding.itemtextview.text = itemsCells[position] } how did u get itemviewholder.viewbinding
what is .viewbinding here
j

John Codeos

12/25/2020, 11:00 AM
from this: class ItemViewHolder(var viewBinding: ItemRowBinding) : RecyclerView.ViewHolder(viewBinding.root)
Check the first code block under the ‘Using View Binding in RecyclerView Adapter’ in the tutorial
s

san

12/25/2020, 11:01 AM
but i didn't get like that
j

John Codeos

12/25/2020, 11:02 AM
I have a demo app at the end of the tutorial, you can test it
s

san

12/25/2020, 11:02 AM
ok
2 Views