How do I set a Java library's custom event listener in Kotlin?



I have been working on an Android project in Kotlin and would like to use this UI library. However, it’s written in Java (and so is the documentation), and I’m not sure how to implement the event listener for the buttons. This is how it’s supposed to be done in Java:

final CircleMenuView menu = (CircleMenuView) findViewById(;
menu.setEventListener(new CircleMenuView.EventListener() {
    public void onMenuOpenAnimationStart(@NonNull CircleMenuView view) {
        Log.d("D", "onMenuOpenAnimationStart");

Does anyone know how I could do the same in Kotlin? Thanks


You can just paste the code in Android Studio and it will suggest to you to convert it to Kotlin code

The same code in Kotlin will be like this

val menu = findViewById<CircleMenuView>(
menu.setEventListener(object : CircleMenuView.EventListener {
    override fun onMenuOpenAnimationStart(view : CircleMenuView) {
        Log.d("D", "onMenuOpenAnimationStart");

Answered By – AmrDeveloper

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More