viewBinding

@JvmName(name = "viewBindingActivity")
inline fun <V : ViewBinding> Activity.viewBinding(crossinline viewBinder: (LayoutInflater) -> V): LazyViewBindingProperty<Activity, V>

Creates an instance of the binding class for the Activity to use.

class VbActivity2 : Activity() {

private val viewBindingProperty = viewBinding(ActivityVbBinding::inflate)
private val mBinding by viewBindingProperty

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(mBinding.root)
}

override fun onDestroy() {
super.onDestroy()
viewBindingProperty.clear()
}

}

Since

0.5.2

See also


@JvmName(name = "viewBindingActivity")
inline fun <V : ViewBinding> ComponentActivity.viewBinding(crossinline viewBinder: (LayoutInflater) -> V): ActivityViewBindingProperty<ComponentActivity, V>

Creates an instance of the binding class for the ComponentActivity to use. ActivityViewBindingProperty will call ActivityViewBindingProperty.clear to clear ViewBinding when the lifecycle of current activity is Lifecycle.State.DESTROYED to prevent memory leaks.

class VbActivity1 : ComponentActivity() {

private val mBinding by viewBinding(ActivityVbBinding::inflate)

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(mBinding.root)
}

}

Since

0.5.2

See also


@JvmName(name = "viewBindingActivity")
inline fun <V : ViewBinding> ComponentActivity.viewBinding(crossinline viewBinder: (View) -> V, crossinline viewProvider: (ComponentActivity) -> View = ::findRootView): ActivityViewBindingProperty<ComponentActivity, V>

Creates an instance of the binding class for the ComponentActivity to use.

class VbActivity3 : ComponentActivity(R.layout.activity_vb) {
private val mBinding by viewBinding(ActivityVbBinding::bind)
}

Since

0.5.2

See also


@JvmName(name = "viewBindingActivity")
inline fun <V : ViewBinding> ComponentActivity.viewBinding(crossinline viewBinder: (View) -> V, @IdRes viewBindingRootId: Int): ActivityViewBindingProperty<ComponentActivity, V>

Creates an instance of the binding class for the ComponentActivity to use.

class VbActivity4 : ComponentActivity(R.layout.activity_vb) {

// root is the root layout id of ActivityVbBinding
private val mBinding by viewBinding(ActivityVbBinding::bind, R.id.root)

}

Since

0.5.2

See also


@JvmName(name = "viewBindingFragment")
inline fun <F : Fragment, V : ViewBinding> Fragment.viewBinding(crossinline viewBinder: (View) -> V, crossinline viewProvider: (F) -> View = Fragment::requireView): ViewBindingProperty<F, V>

Creates an instance of the binding class for the Fragment to use.

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

private val mBinding by viewBinding(FragmentSenderBinding::bind)

}

Since

0.5.2

See also


@JvmName(name = "viewBindingFragment")
inline fun <F : Fragment, V : ViewBinding> Fragment.viewBinding(crossinline viewBinder: (View) -> V, @IdRes viewBindingRootId: Int): ViewBindingProperty<F, V>

Creates an instance of the binding class for the Fragment to use.

class VbFragment2 : DialogFragment(R.layout.fragment_sender) {

val mBinding by viewBinding(FragmentSenderBinding::bind, R.id.fragment_sender_root)

}

Since

0.5.2

See also


@JvmName(name = "viewBindingViewGroup")
inline fun <V : ViewBinding> ViewGroup.viewBinding(crossinline viewBinder: (View) -> V, crossinline viewProvider: (ViewGroup) -> View = { this }): LazyViewBindingProperty<ViewGroup, V>
@JvmName(name = "viewBindingViewGroup")
inline fun <V : ViewBinding> ViewGroup.viewBinding(crossinline viewBinder: (View) -> V, @IdRes viewBindingRootId: Int): LazyViewBindingProperty<ViewGroup, V>

Creates an instance of the binding class for the ViewGroup to use.

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

private val mBinding by viewBinding(ViewgroupVbBinding::bind)
// Or
// private val mBinding by viewBinding(ViewgroupVbBinding::bind, R.id.root)

init {
inflate(context, R.layout.viewgroup_vb, this)
}

}

Since

0.5.2

See also


@JvmName(name = "viewBindingViewHolder")
inline fun <V : ViewBinding> RecyclerView.ViewHolder.viewBinding(crossinline viewBinder: (View) -> V, crossinline viewProvider: (RecyclerView.ViewHolder) -> View = RecyclerView.ViewHolder::itemView): LazyViewBindingProperty<RecyclerView.ViewHolder, V>

Creates an instance of the binding class for the RecyclerView.ViewHolder to use.

class ArticleVH(itemView: View) : RecyclerView.ViewHolder(itemView) {
private val binding by viewBinding(ItemArticleBinding::bind)
val title = binding.articleTitle
val shareUser = binding.articleShareUser
}

Since

0.5.2

See also


@JvmName(name = "viewBindingViewHolder")
inline fun <V : ViewBinding> RecyclerView.ViewHolder.viewBinding(crossinline viewBinder: (View) -> V, @IdRes viewBindingRootId: Int): LazyViewBindingProperty<RecyclerView.ViewHolder, V>

Creates an instance of the binding class for the RecyclerView.ViewHolder to use.

class ArticleVH(itemView: View) : RecyclerView.ViewHolder(itemView) {
private val binding by viewBinding(ItemArticleBinding::bind, R.id.article_root)
val title = binding.articleTitle
val shareUser = binding.articleShareUser
}

Since

0.5.2

See also