- Step 1 :- First of all you have to take item for show repeatidly
@Composable
fun CustomItem(person: Person) {
Row(
modifier = Modifier
.background(Color.LightGray)
.fillMaxWidth()
.padding(24.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(12.dp)
) {
Text(
text = "${person.age}",
color = Color.Black,
fontSize = Typography.headlineLarge.fontSize,
fontWeight = FontWeight.Bold
)
Text(
text = person.firstName,
color = Color.Black,
fontSize = Typography.headlineMedium.fontSize,
fontWeight = FontWeight.Normal
)
Text(
text = person.lastName,
color = Color.Black,
fontSize = Typography.headlineMedium.fontSize,
fontWeight = FontWeight.Normal
)
}
}
- Step 2 :-
Take data model
data class Person(
val id: Int,
val firstName: String,
val lastName: String,
val age: Int
)
- Step 3 :-
You have to take in LazyColumn
items(items = personList) { person ->
Card(
modifier = Modifier
.padding(8.dp)
.fillMaxWidth()
.clickable {
Log.d(
"PersonClick",
"Clicked on: ${person.id} ${person.lastName}"
)
},
shape = ShapeDefaults.Medium,
elevation = CardDefaults.cardElevation(7.dp)
) {
CustomItem(person = person)
}
}
- Step 4 :-
Screenshots are :-
0 Comments