create viewmodel for views android code example

Example 1: kotlin binding views to activity

// Adding this to your build.gradle (Module level)

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    //Added:
    id 'kotlin-kapt'
    id 'kotlin-android-extensions'
}


// And having this in your layout
<Button
	android:id="@+id/btn_finish"
    (...)

// You ca use this in the .kt file
btn_finish.setOnClickListener {
	// Do Something
}

Example 2: how to use by viewModels()

compileOptions {
        sourceCompatibility = 1.8
        targetCompatibility = 1.8
    }

    kotlinOptions {
        jvmTarget = "1.8"
    }