viewBinding
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
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
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
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
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
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
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
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
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