Skip to content

Instantly share code, notes, and snippets.

@satadii11
Last active November 25, 2021 08:09
Show Gist options
  • Save satadii11/3ba8b0036e8e8fb609bdea018158c9c5 to your computer and use it in GitHub Desktop.
Save satadii11/3ba8b0036e8e8fb609bdea018158c9c5 to your computer and use it in GitHub Desktop.
class MainActivity : AppCompatActivity() {
private val viewModel by viewModels<MainViewModel>()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
val count by viewModel.count.collectAsState()
MdcTheme {
Row(
modifier = Modifier
.fillMaxSize()
.padding(horizontal = 16.dp),
verticalAlignment = Alignment.CenterVertically
) {
Button(onClick = { viewModel.decrease() }) {
Text("Kurang")
}
Text(
"Jumlah: $count",
modifier = Modifier
.weight(1f)
.align(Alignment.CenterVertically),
textAlign = TextAlign.Center
)
Button(onClick = { viewModel.increase() }) {
Text("Tambah")
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment