Skip to content
Advertisement

How can I get all the events of the buttons on a screen on android in a single method using the kotlin?

I am developing a Calculator for my android learning using kotlin. To get the numbers select to users, I need to set the code below:

JavaScript

Is it possible to centrelize the event handling of all buttons in the single class or method?

I would like to a generic solution to reduce the code

Does anyone know a solution?

Advertisement

Answer

this is a standard way to handle click events in kotlin. create Function click listeners in your Class. call this function in onCreate function.

JavaScript

extend OnclickListner to your Activity/Fragment.

JavaScript

then override onClick function and write your onClick Logic.

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement