Home > Enterprise >  Background selector not working in jetpack compose
Background selector not working in jetpack compose

Time:07-30

Hello I am using lazycolumn inside column to show my nested list. When I am trying to click on single item, it's clicking on whole another items as well instead of single and color is not changing as well.

 binding.itemComposable.setContent {
     val interactionSource = remember { MutableInteractionSource() }
     val isPressed by interactionSource.collectIsPressedAsState()
     val backgroundColor = if (isPressed) DuckEggBlue else OffWhite
     val clickable = Modifier.clickable(
         interactionSource = interactionSource,
         indication = LocalIndication.current
     ) {
         println("Item Click")
     }
     Column(
         modifier = Modifier
             .fillMaxSize(),
         verticalArrangement = Arrangement.spacedBy(12.dp)
     ) {
         val options = getOptions()
         options.forEachIndexed { _, optionText ->
             Card(
                 shape = RoundedCornerShape(4.dp),
                 modifier = Modifier.then(clickable)
             ) {
                 Text(
                     modifier = Modifier
                         .fillMaxWidth()
                         .background(backgroundColor)
                         .padding(16.dp),
                     text = optionText,
                     style = Typography.h3,
                     fontWeight = FontWeight.Medium,
                     color = Slate
                 )
             }
         }
     }
 }

You can check in the enter image description here

  • Related