Skip to content

matsudamper/ViewBindingUtil

Repository files navigation

ViewBindingUtil

This is the DataBindingUtil function created for ViewBinding. https://developer.android.com/reference/android/databinding/DataBindingUtil

Usage

gradle

repositories {
  maven { url 'https://jitpack.io' }
}
dependencies {
  implementation 'com.github.matsudamper:ViewBindingUtil:${version}'
}

Sample

https://github.com/matsudamper/ViewBindingUtil/tree/master/app/src/main/java/net/matsudamper/viewbindingutil

  • 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>()
}

About

DataBindingUtil function created for ViewBinding.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages