I saw I lot of videos says that the Kotlin can recognize the buttons (views) automatically in MainActivity.kt I try this but it doesn't work for me in android studio 4.1 when I'm using the usual code with :
var button_name = findViewById(R.id.buttonName)
it works fine but when I'm using the code directly like this :
buttonName.setonclicklistiner{}
the IDE doesn't recognize the button
PS : this the imports in the mainactivity
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
What can i do for access my button or textView automatically in MainActivity.kt
In build.gradle(module) make sure plugins contains following 3 plugins -
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-android-extensions'
}
Open build_gradle(:app) and make sure you have these two lines in dependencies block
dependencies {
apply plugin : "kotlin-android"
apply plugin : "kotlin-android-extensions"
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With