Jetpack Compose Listview OnItem Click Listener Events
Last updated Aug 24, 2022In this Jetpack Compose tutorial we will learn about How to capture Listview Item Click Events with Compose Listview. In Android application Listview will used to display large amount of data. This data might be came from Internet or local data, we will use LazyRow and LazyColumn Jetpack Compose widgets to display these data.
To capture each list item data on Click event we will add Click Listener on Modifier property
Let get started about handle Listview ItemClickListener with Modifier Clickable() property.
Step 1: Create Simple Compose application. To create new Jetpack project in Android studio please refer how to create first Project in Android studio using Jetpack compose
Step 2: Create Listview with multiple data. Read Create Listview with compose in android
Step 3: Let Create List Item which will display image and title based on previous example
Card( ) { // on below line we are adding content
|
This will display each individual list item data. Let add click event by set clickable property to the Card compose Modifier
Card( ) |
Step 4: Let run application and click on each item you can capture each item click event and we can get the current item data
![]() |
Complete code for Listview OnItemClickListener example
package com.example.listviewclick class MainActivity : ComponentActivity() { val platformList = ArrayList<Platform>()
@ExperimentalUnitApi ) { // on below line we are adding content
|
Conclusion: In this Compose tutorial we covered how to capture Listview Item Click Events with Modifier Clickable() property
Article Contributed By :
|
|
|
|
847 Views |