“不支持“ RequestCursorupdates” OutlinedTextfield的错误

发布于 2025-02-11 04:49:38 字数 3392 浏览 1 评论 0原文

我有几个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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不醒的梦 2025-02-18 04:49:38

找到了这个问题。我必须这样做:

fun setListItemStateValue(stateToEdit: String, stateValue: String) {
  val item = shoppingListItemState.value
  when (stateToEdit) {
      "Name" -> shoppingListItemState.value = item.copy(name = stateValue)
      "Category" -> shoppingListItemState.value = item.copy(category = stateValue)
      "Quantity" -> shoppingListItemState.value = item.copy(quantity = stateValue)
      "Unit" -> shoppingListItemState.value = item.copy(unit = stateValue)
      "PPU" -> shoppingListItemState.value = item.copy(ppu = stateValue)
      "Notes" -> shoppingListItemState.value = item.copy(notes = stateValue)
      "HasImage" -> shoppingListItemState.value = item.copy(hasImage = stateValue.toBoolean())
      "ImageUri" -> shoppingListItemState.value = item.copy(imageUri = stateValue.toUri())
  }
}

Found the issue. I had to do this instead:

fun setListItemStateValue(stateToEdit: String, stateValue: String) {
  val item = shoppingListItemState.value
  when (stateToEdit) {
      "Name" -> shoppingListItemState.value = item.copy(name = stateValue)
      "Category" -> shoppingListItemState.value = item.copy(category = stateValue)
      "Quantity" -> shoppingListItemState.value = item.copy(quantity = stateValue)
      "Unit" -> shoppingListItemState.value = item.copy(unit = stateValue)
      "PPU" -> shoppingListItemState.value = item.copy(ppu = stateValue)
      "Notes" -> shoppingListItemState.value = item.copy(notes = stateValue)
      "HasImage" -> shoppingListItemState.value = item.copy(hasImage = stateValue.toBoolean())
      "ImageUri" -> shoppingListItemState.value = item.copy(imageUri = stateValue.toUri())
  }
}
时光暖心i 2025-02-18 04:49:38

当我在我的一个房间桌子中添加了一个Bytearray字段时,我也遇到了同样的问题。希望这对某人有帮助。

从中走了:

@Entity  
data class FeatureXX(
    @PrimaryKey(autoGenerate = true)
    val id:Int,
    val input0:String,
    val inputImage: ByteArray
)

data class FeatureXXState(
    val initialStateInput0:String = "",
    val initialStateImage:ByteArray = ByteArray(0)
) 

sealed class ModifyFeatureXXEvent{
    data class EnteredValueInput0(val value0:String):ModifyFeatureXXEvent()
    data class EnteredImageValue(val imgValue:ByteArray):ModifyFeatureXXEvent()    
}

class ThisViewModel : VieModel(){
    private val _state0 = mutableStateOf(FeatureXXState(initialStateInput0 = ""))
    val state0: State<FeatureXXState> = _state0

    private val _stateImage = mutableStateOf(initialStateImage = ByteArray(0))
    val stateImage: State<FeatureXXState> = _stateImage

    fun onEvent(event:ModifyFeatureXXEvent){
        when(event){
            is ModifyFeatureXXEvent.EnteredValueInput0 -> {
                _state0.value = state0.value.copy(initialStateInput0 = event.value0)
            }
            is ModifyFeatureXXEvent.EnteredImageValue -> {
                _stateImage.value = stateImage.value.copy(initialStateImage = event.imgValue)
            }
        }
    }
}

我的组合几乎与您一样。

是什么解决了我的问题 - &gt;

@Entity  
data class FeatureXX(
    @PrimaryKey(autoGenerate = true)
    val id:Int,
    val input0:String,
    val inputImage: ByteArray
){
    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false

        other as FeatureXX
        if (id != other.id) return false
        if (input0 != other.input0) return false
        if (!inputImage.contentEquals(other.inputImage)) return false
        return true
    }
    override fun hashCode(): Int {
        var result = id
        result = 31 * result + input0.hashCode()
        result = 31 * result + inputImage.contentHashCode()
        return result
   }

然后 - &gt;

data class FeatureXXState(
    val initialStateInput0:String = "",
    val initialStateImage:ByteArray = ByteArray(0)
){
  override fun equals(other: Any?): Boolean {
    if (this === other) return true
    if (javaClass != other?.javaClass) return false

    other as F3TextFieldState

    if (initialStateInput0 != other.initialStateInput0) return false
    if (!initialStateImage.contentEquals(other.initialStateImage)) return false
    return true
    }
    override fun hashCode(): Int {
        var result = initialStateInput0.hashCode() 
        result = 31 * result + initialStateImage.contentHashCode()
        return result
   }

最后 - &gt;

sealed class ModifyFeatureXXEvent{
    data class EnteredValueInput0(val value0:String):ModifyFeatureXXEvent()
    data class EnteredImageValue(val imgValue:ByteArray):ModifyFeatureXXEvent(){
    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false

        other as EnteredImageValue

        if (!imgValue.contentEquals(other.imgValue)) return false

        return true
    }
    override fun hashCode(): Int {
        return imgValue.contentHashCode()
    }    
}

无需更改查看模型。

I had the same issue when I added a ByteArray Field to one of my Room tables. Hopefully this helps someone.

Went from this:

@Entity  
data class FeatureXX(
    @PrimaryKey(autoGenerate = true)
    val id:Int,
    val input0:String,
    val inputImage: ByteArray
)

data class FeatureXXState(
    val initialStateInput0:String = "",
    val initialStateImage:ByteArray = ByteArray(0)
) 

sealed class ModifyFeatureXXEvent{
    data class EnteredValueInput0(val value0:String):ModifyFeatureXXEvent()
    data class EnteredImageValue(val imgValue:ByteArray):ModifyFeatureXXEvent()    
}

class ThisViewModel : VieModel(){
    private val _state0 = mutableStateOf(FeatureXXState(initialStateInput0 = ""))
    val state0: State<FeatureXXState> = _state0

    private val _stateImage = mutableStateOf(initialStateImage = ByteArray(0))
    val stateImage: State<FeatureXXState> = _stateImage

    fun onEvent(event:ModifyFeatureXXEvent){
        when(event){
            is ModifyFeatureXXEvent.EnteredValueInput0 -> {
                _state0.value = state0.value.copy(initialStateInput0 = event.value0)
            }
            is ModifyFeatureXXEvent.EnteredImageValue -> {
                _stateImage.value = stateImage.value.copy(initialStateImage = event.imgValue)
            }
        }
    }
}

My Composables were pretty much like yours.

What Solved My Issue ->

@Entity  
data class FeatureXX(
    @PrimaryKey(autoGenerate = true)
    val id:Int,
    val input0:String,
    val inputImage: ByteArray
){
    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false

        other as FeatureXX
        if (id != other.id) return false
        if (input0 != other.input0) return false
        if (!inputImage.contentEquals(other.inputImage)) return false
        return true
    }
    override fun hashCode(): Int {
        var result = id
        result = 31 * result + input0.hashCode()
        result = 31 * result + inputImage.contentHashCode()
        return result
   }

Then ->

data class FeatureXXState(
    val initialStateInput0:String = "",
    val initialStateImage:ByteArray = ByteArray(0)
){
  override fun equals(other: Any?): Boolean {
    if (this === other) return true
    if (javaClass != other?.javaClass) return false

    other as F3TextFieldState

    if (initialStateInput0 != other.initialStateInput0) return false
    if (!initialStateImage.contentEquals(other.initialStateImage)) return false
    return true
    }
    override fun hashCode(): Int {
        var result = initialStateInput0.hashCode() 
        result = 31 * result + initialStateImage.contentHashCode()
        return result
   }

Finally ->

sealed class ModifyFeatureXXEvent{
    data class EnteredValueInput0(val value0:String):ModifyFeatureXXEvent()
    data class EnteredImageValue(val imgValue:ByteArray):ModifyFeatureXXEvent(){
    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false

        other as EnteredImageValue

        if (!imgValue.contentEquals(other.imgValue)) return false

        return true
    }
    override fun hashCode(): Int {
        return imgValue.contentHashCode()
    }    
}

No change to view model.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文