VOOZH about

URL: https://www.geeksforgeeks.org/kotlin/pass-an-on-click-event-to-a-function-in-android-jetpack-compose/

⇱ Pass an On-Click Event to a Function in Android Jetpack Compose - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Pass an On-Click Event to a Function in Android Jetpack Compose

Last Updated : 23 Jul, 2025

In Jetpack Compose, we can create functions to create any type of UI element. Suppose, we create a function to create a Button, we can use it multiple times to create multiple buttons. While creating multiple Buttons, we can add functionality to them to perform any given task, which we call On-Click Event. So in this article, we will show you how you could create such a function and pass an On-Click Event to another Function in Android using Jetpack Compose. Follow the below steps once the IDE is ready.

Step by Step Implementation

Step 1: Create a New Project in Android Studio

To create a new project in the Android Studio, please refer to How to Create a new Project in Android Studio with Jetpack Compose.

Step 2: Working with the MainActivity.kt file

Go to the MainActivity.kt file and refer to the following code. Comments are added inside the code to understand the code in more detail.

In this we will creating a custom Button Composable and pass it in out main composable.

MainActivity.kt:

Output:

Comment
Article Tags:

Explore