SolarBinding


A SolarBinding with databinding for andorid

License

Dependency Gradle

Add below codes to your root build.gradle file (not your module build.gradle file).

allprojects {
    repositories {
        maven { url "https://jitpack.io" }
    }
}

And add a dependency code to your module's build.gradle file.

plugins {
  id 'kotlin-kapt'
}

buildFeatures {
  dataBinding true
}
dependencies {
  implementation 'com.github.KennethSS:SolarBinding:1.0.2'
}

Usage

Basic Example

Prepare to making binding xml

<?xml version="1.0" encoding="utf-8"?>
<layout ...>

    <androidx.constraintlayout.widget.ConstraintLayout>
      ...  
    </androidx.constraintlayout.widget.ConstraintLayout>
</layout>

Activity

class MainActivity : BindingActivity() {

    private val binding by binding<ActivityMainBinding>(R.layout.activity_main)

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        with(binding) {
            centerTv.text = "Hello World!"
        }
    }
}

Fragment

class SampleFragment : BindingFragment<FragmentSampleBinding>(){
    override val layoutRes: Int = R.layout.fragment_sample

    override fun onViewCreated(bind: FragmentSampleBinding, savedInstanceState: Bundle?) {
        bind.sampleTv.text = "Hello World!"
    }
}