primix
primix

Reputation: 405

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(R.id.circle_menu);
menu.setEventListener(new CircleMenuView.EventListener() {
    @Override
    public void onMenuOpenAnimationStart(@NonNull CircleMenuView view) {
        Log.d("D", "onMenuOpenAnimationStart");
    }
}

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

Upvotes: 1

Views: 364

Answers (2)

Vineed Gangadharan
Vineed Gangadharan

Reputation: 31

You could also try something like this

    val menu = findViewById<CircleMenuView>(R.id.circle_menu)
    menu.setEventListener{view->
       //Listener code goes here
    }

Upvotes: 0

AmrDeveloper
AmrDeveloper

Reputation: 4702

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>(R.id.circle_menu)
menu.setEventListener(object : CircleMenuView.EventListener {
    override fun onMenuOpenAnimationStart(view : CircleMenuView) {
        Log.d("D", "onMenuOpenAnimationStart");
    }
})

Upvotes: 2

Related Questions