[Android] Released library DataBinding-ktx to simplify variable declaration of DataBinding
DataBinding-ktx 2.0.0 has been released.
Original article is below.
What is DataBinding-ktx
A library that simplifies DataBinding variable declaration using Kotlin’s Delegated Properties . By using this library, you can declare properties as follows.
Library is here → https://github.com/wada811/DataBinding-ktx
What makes you happy with DataBinding-ktx
Usually, when you execute DataBinding, you write as follows.
It is long to the side. If the display is narrow, you can not see the description of the layout file without scrolling. You have to scroll to the side to check the layout.
Or you can write it using lazy as follows.
In that case, it is initialized when using the variable of binding for the first time.
( I hate to be MainActivityBinding! …)
If you use DataBinding-ktx, you can shorten the layout by simply passing the layout file to the bind function when declaring properties.
How to use DataBinding-ktx
See wada811 / DataBinding-ktx .
app.gradle
repositories {
maven { url "https://jitpack.io" }
}dependencies {
implementation 'com.github.wada811:DataBinding-ktx:1.0.0'
}
Activity
class MainActivity : AppCompatActivity() {
private val binding: MainActivityBinding by bind(R.layout.main_activity)
}
Fragment
class MainFragment : Fragment() {
private val binding: MainFragmentBinding by bind(R.layout.main_fragment)
}
that’s all.