This is the DataBindingUtil function created for ViewBinding. https://developer.android.com/reference/android/databinding/DataBindingUtil
repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'com.github.matsudamper:ViewBindingUtil:${version}'
}
- Basic Usage
val binding = ViewBindingUtil.inflate<ActivityMainBinding>(layoutInflater)
val view = layoutInflater.inflate(R.layout.activity_main, null)
val binding = ViewBindingUtil.bind<ActivityMainBinding>(view)
- Activity or Fragment delegation
binding : HogeBinding = inflateViewBinding()
- AndroidX Activity and Fragment delegation
class SampleActivity : AppCompatActivity(R.layout.activity_main) {
private val binding by bindViewBinding<ActivityMainBinding>()
}
class BindSampleFragment : Fragment(R.layout.fragment_main) {
// Considering the reproducibility of the view
private val binding by bindViewBinding<FragmentMainBinding>()
}