Button onClick attribute is none if activity written in Kotlin

It seems like the designer does not support Kotlin yet. Here are some solution:

XML (Not Recommended)

Add the following line to your Button tag. This is exactly what the designer will do.

android:onClick="sendMessage"

Old Fashion

No need to add anything.

val button = findViewById<Button>(R.id.Button)
button.setOnClickListener {

}

kotlin-android-extensions (Recommended)

Add apply plugin: "kotlin-android-extensions" to your build.gradle

// button is the Button id
button.setOnClickListener {

}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)