Sobes.tech
Junior — Middle

How to implement click event handling for a button in Jetpack Compose?

sobes.tech AI

Answer from AI

In Jetpack Compose, handling a button click is implemented using the onClick parameter in the Button component. Example:

Button(onClick = { 
    // Actions on click
    println("Button pressed")
}) {
    Text("Press me")
}

In the lambda expression, onClick, you specify the code that should be executed when the button is pressed. This can be a function call, a state change, or navigation.

Thus, event handling in Compose is very declarative and simple.