📄 build.gradle(Module)
plugins {
...
id 'kotlin-kapt'
}
android {
...
dataBinding{
enabled = true
}
}
dependencies {
...
kapt 'com.android.databinding:compiler:3.5.3'
}
- 'kotlin-kapt' plugin / databinding{ enabled = true } / dependencies 추가
📄 activity_main.xml
<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".news_list.MainActivity" />
</layout>
📄 MainActivity.kt
class MainActivity : AppCompatActivity() {
private lateinit var binding: ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = DataBindingUtil.setContentView(this, R.layout.activity_main)
}
}