When user type in TextField it will call onValueChange{} callback. but when we set the value in TextField the onValueChange{} callback will not call.
I found https://issuetracker.google.com/issues/172239032 open issue.
Below is a code snippet where I have defined TextField.
OutlinedTextField(
value = enteredValues[index],
onValueChange = { value: String ->
onTextFieldValueChange(value)
},
singleLine = true,
keyboardOptions = keyboardOption,
colors = textFieldColors,
)
To get the callback of onValueChange I want to call the keypress event programmatically so might be I will get onValueChange callback. Can anyone give me a solution? how to use keypress programmatically in jetpack compose?
I have no idea why you want to do this, but here it is a suggestion/workaround...
You can simulate the key event like below (credit for this answer):
Then, you can call this function passing the key code you want to send...
Notice that will only work if the
TextField
has focus, this is why I'm using theFocusRequester
.