“不支持“ RequestCursorupdates” OutlinedTextfield的错误
我有几个outtextfield
输入,并且在使用Data Class
作为viewModel
中的状态持有人时,输入它们无能为力。 LogCat每次我从软键板中键入一个字符时,返回以下debug
错误。但是,LogCat不会抛出任何运行时异常。我该如何解决?
W/RecordingIC: requestCursorUpdates is not supported
数据类
data class ShoppingListItemState(
val name: String = "",
val category: String = "",
val quantity: String = "",
val unit: String = "",
val ppu: String = "",
val notes: String = "",
val hasImage: Boolean = false,
val imageUri: Uri? = null
)
viewModel
class ShoppingListScreenViewModel(): ViewModel() {
val shoppingListItemState = mutableStateOf(ShoppingListItemState())
fun setListItemStateValue(stateToEdit: String, stateValue: String) {
val item = shoppingListItemState.value
when (stateToEdit) {
"Name" -> item.copy(name = stateValue)
"Category" -> item.copy(category = stateValue)
"Quantity" -> item.copy(quantity = stateValue)
"Unit" -> item.copy(unit = stateValue)
"PPU" -> item.copy(ppu = stateValue)
"Notes" -> item.copy(notes = stateValue)
"HasImage" -> item.copy(hasImage =stateValue.toBoolean())
"ImageUri" -> item.copy(imageUri = stateValue.toUri())
}
shoppingListItemState.value = item
}
}
customoutlinedTextfield呼叫
val shoppingListScreenViewModel: ShoppingListScreenViewModel = viewModel()
CustomOutlinedTextField(
modifier = Modifier
.fillMaxWidth()
.onPreviewKeyEvent {
if (it.key == Key.Tab) {
focusManager.moveFocus(FocusDirection.Down)
true
} else {
false
}
},
label = stringResource(id = R.string.item_name),
inputVal = shoppingListScreenViewModel.shoppingListItemState.value.name,
isSingleLine = true,
keyboardOptions = KeyboardOptions.Default.copy(
capitalization = KeyboardCapitalization.Sentences,
autoCorrect = false,
keyboardType = KeyboardType.Text,
imeAction = ImeAction.Next
),
keyboardActions = KeyboardActions(
onNext = { focusManager.moveFocus(FocusDirection.Down) }
)
) { shoppingListScreenViewModel.setListItemStateValue("Name", it) }
customoutoutlinedTextfield composable
@Composable
fun CustomOutlinedTextField(
modifier: Modifier = Modifier,
label: String = "",
inputVal: String,
isSingleLine:
Boolean = false,
maxLines: Int = 0,
keyboardOptions: KeyboardOptions = KeyboardOptions.Default,
keyboardActions: KeyboardActions = KeyboardActions.Default,
onValChange: (String) -> Unit
) {
OutlinedTextField(
value = inputVal,
onValueChange = { onValChange(it) },
label = { Text(text = label) },
singleLine = isSingleLine,
maxLines = maxLines,
keyboardOptions = keyboardOptions,
keyboardActions = keyboardActions,
modifier = modifier
)
}
I have several OutlinedTextField
inputs, and typing into them does nothing while using a Data Class
as the state holder in the ViewModel
. Logcat returns the following Debug
error each time I type a character from the softkeyboard. However, Logcat does not throw any runtime exceptions. How can I fix this?
W/RecordingIC: requestCursorUpdates is not supported
Data Class
data class ShoppingListItemState(
val name: String = "",
val category: String = "",
val quantity: String = "",
val unit: String = "",
val ppu: String = "",
val notes: String = "",
val hasImage: Boolean = false,
val imageUri: Uri? = null
)
ViewModel
class ShoppingListScreenViewModel(): ViewModel() {
val shoppingListItemState = mutableStateOf(ShoppingListItemState())
fun setListItemStateValue(stateToEdit: String, stateValue: String) {
val item = shoppingListItemState.value
when (stateToEdit) {
"Name" -> item.copy(name = stateValue)
"Category" -> item.copy(category = stateValue)
"Quantity" -> item.copy(quantity = stateValue)
"Unit" -> item.copy(unit = stateValue)
"PPU" -> item.copy(ppu = stateValue)
"Notes" -> item.copy(notes = stateValue)
"HasImage" -> item.copy(hasImage =stateValue.toBoolean())
"ImageUri" -> item.copy(imageUri = stateValue.toUri())
}
shoppingListItemState.value = item
}
}
CustomOutlinedTextField Call
val shoppingListScreenViewModel: ShoppingListScreenViewModel = viewModel()
CustomOutlinedTextField(
modifier = Modifier
.fillMaxWidth()
.onPreviewKeyEvent {
if (it.key == Key.Tab) {
focusManager.moveFocus(FocusDirection.Down)
true
} else {
false
}
},
label = stringResource(id = R.string.item_name),
inputVal = shoppingListScreenViewModel.shoppingListItemState.value.name,
isSingleLine = true,
keyboardOptions = KeyboardOptions.Default.copy(
capitalization = KeyboardCapitalization.Sentences,
autoCorrect = false,
keyboardType = KeyboardType.Text,
imeAction = ImeAction.Next
),
keyboardActions = KeyboardActions(
onNext = { focusManager.moveFocus(FocusDirection.Down) }
)
) { shoppingListScreenViewModel.setListItemStateValue("Name", it) }
CustomOutlinedTextField Composable
@Composable
fun CustomOutlinedTextField(
modifier: Modifier = Modifier,
label: String = "",
inputVal: String,
isSingleLine:
Boolean = false,
maxLines: Int = 0,
keyboardOptions: KeyboardOptions = KeyboardOptions.Default,
keyboardActions: KeyboardActions = KeyboardActions.Default,
onValChange: (String) -> Unit
) {
OutlinedTextField(
value = inputVal,
onValueChange = { onValChange(it) },
label = { Text(text = label) },
singleLine = isSingleLine,
maxLines = maxLines,
keyboardOptions = keyboardOptions,
keyboardActions = keyboardActions,
modifier = modifier
)
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
找到了这个问题。我必须这样做:
Found the issue. I had to do this instead:
当我在我的一个房间桌子中添加了一个Bytearray字段时,我也遇到了同样的问题。希望这对某人有帮助。
从中走了:
我的组合几乎与您一样。
是什么解决了我的问题 - >
然后 - >
最后 - >
无需更改查看模型。
I had the same issue when I added a ByteArray Field to one of my Room tables. Hopefully this helps someone.
Went from this:
My Composables were pretty much like yours.
What Solved My Issue ->
Then ->
Finally ->
No change to view model.