I cant get the Card in the LazyColumn to check if the number is in val guestNumbers and then change the color on the Card.
But the numbers in val guestNumbers changes on startup.
Is the Card the right stuff to use or should i use buttons?
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
val guestNumbers = rememberSaveable {
mutableStateOf(mutableSetOf<Int>(10,11,2,22))
}
NumberGuessingGameTheme {
Scaffold(
topBar = {
TopAppBar {
}
}
) {
Row(modifier = Modifier.fillMaxSize()
) {
Box(
modifier = Modifier
.fillMaxSize()
.weight(4f)
.background(color = Color.LightGray)
) {
Text(
text = "1F",
style = MaterialTheme.typography.caption
)
}
Box(
modifier = Modifier
.fillMaxSize()
.weight(1f)
.background(color = Color.LightGray)
) {
LazyColumn {
items(1000 + 1) {
Card(modifier = Modifier
.fillMaxSize()
.padding(5.dp)
//.background(if ("$it".toInt() !in guestNumbers.value) Color.Green else Color.Red)
.clickable {
guestNumbers.value.add("$it".toInt())
Log.d("Tag", "${guestNumbers.value}")
},
elevation = 10.dp,
backgroundColor = if ("$it".toInt() in guestNumbers.value) Color.Red else Color.LightGray
) {
Text(text = "$it", fontSize = 28.sp, textAlign = TextAlign.Center)
}
}
}
}
}
}
}
}
}
}