Skip to content

ViewBinding delegate

Quick start

Activity

Version 0.5.2

private val mBindings by 
    viewBinding(ActivityWaveProgressViewBinding::inflate)

Fragment

Version 0.5.2

class VbFragment1 : Fragment(R.layout.fragment_sample) {

    private val mBinding by 
        viewBinding(FragmentSampleBinding::bind)

}

ViewHolder

Version 0.5.2

class MyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
    private val binding by viewBinding(ItemPersonBinding::bind)
    val firstName = binding.firstName
    val lastName = binding.lastName
}

ViewGroup

Version 0.5.2

class VbViewGroup1 @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
    LinearLayout(context, attrs) {

    private val binding by viewBinding(ViewgroupVbBinding::bind)

}

Sample code

Sample code