How do I set the custom interface like OnClickListener


Hey,I try to use Kotlin for my application。Then have a question.
We can set View’s OnClickListener like this
I have a custom interface
public interface Itest {
public fun runMyCallback(content:String?)
in a custom class.
So I want to the custom interface to clas like view.setOnClickListener{println(“clicked”}
How to do it.


Here’s an exerpt from my own Android app that uses listeners:

val myListener = View.OnClickListener {


If you have a custom interface that extends View.OnClickListener, you could use that here instead and it should also work just fine.


And while you’re converting things:

liteButton.onClickListener = myListener
toolButton.onClickListener = myListener
numbersButton.onClickListener = myListener

Note that IDEA should have placed warnings on these lines of your original code.


Those “buttons” come from the kotlin-android-extensions’s synthetic properties. I just tried the substitution you suggest and it unfortunately doesn’t work. Not defined. Maybe that was in an earlier version?


It’s Not working??