I am using jetpack-compose in my project, and don't know how to change a TextField
's value from my ViewModel.
In my Activity:
...
@Composable
fun myView() {
var dName = remember {
mutableStateOf(TextFieldValue(""))
}
TextField(
value = dName.value,
onValueChange = { dName.value = it },
modifier = Modifier.fillMaxWidth()
)
}
...
In my ViewModel:
...
var dName = MutableStateFlow("")
...
I want to call dName.value = "test"
in my ViewModel and change the shown value in the TextField
. How can I accomplish this?
var textFieldValue by mutableStateOf(TextFieldValue())
? – Sulfanilamide