如何使用JetPack组合Android以编程为TextField的Keypress事件?
当用户输入TextField时,它将调用OnValueChange {}回调。但是,当我们在TextField中设置值时,onValueChange {}回调将无法调用。
我发现 https://issuetracker.google.com/issues/issues/172239032 开放问题。
以下是我定义了Textfield的代码段。
OutlinedTextField(
value = enteredValues[index],
onValueChange = { value: String ->
onTextFieldValueChange(value)
},
singleLine = true,
keyboardOptions = keyboardOption,
colors = textFieldColors,
)
要获取OnValueChange的回调,我想以编程方式调用按键事件,所以我可能会得到OnValueChange回调。谁能给我解决方案?如何在JetPack组合中以编程方式使用按键?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道您为什么要这样做,但是这是一个建议/解决方法...
您可以模拟以下的关键事件(这个答案):
然后,您可以调用此功能传递要发送的关键代码...
注意仅在
textfield
具有焦点时才有效,这就是为什么我正在使用FocusRequester
。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
.