Small Android library for the usage of ViewBindings in your Activities and Fragments without the usual boilerplate code
Simply pass the respective ViewBinding
subclass both as type and constructor argument during the initialization of your UI controller class. The boilerplaty stuff will subsequently be taken care of and you can just use the binding in your code.
The retrieval of the respectively required inflate
method is carried out by means of reflection.
-
Activity
class YourActivity: ViewBoundActivity<YourActivityBinding>(YourActivityBinding::class.java)
YourActivityBinding
will be inflated in theonCreate
lifecycle method and is thereupon accessible via thebinding
property -
Fragment
class YourFragment: ViewBoundFragment<YourFragmentBinding>(YourFragmentBinding::class.java)
Same goes for Fragments, only that here the binding inflation happens in
onCreateView
. Also, the binding will be nulled inonDestroyedView
to prevent memory leaks.
implementation 'com.github.w2sv:viewboundcontroller:x.y.z'
or get the latest snapshot from a certain branch:
implementation 'com.github.w2sv:viewboundcontroller:<BRANCH-NAME>-SNAPSHOT'