gpt4 book ai didi

android - 找不到符号类数据绑定(bind) impl

转载 作者:行者123 更新时间:2023-12-02 13:30:52 24 4
gpt4 key购买 nike

抱歉,我不能直接在帖子中发布图片,因为它说我必须至少有 10 名声望才能发布。

我像这样在android studio中创建了一个xml
Xml

并像这样在 View 模型中创建了 2 个变量

private val _loadingText = MutableLiveData<String>()
val loadingText: LiveData<String> = _loadingText

然后像这样在我的对话框 View 中实现数据绑定(bind)
val dialogView = layoutInflater.inflate(R.layout.dialog_custom_loading, dialog_root)
val binding = DialogCustomLoadingBinding.inflate(layoutInflater, dialogView as ViewGroup, false)
binding.viewModel = viewModel
loading = Dialog(this)
loading.setContentView(binding.root)

但是当我运行代码时,它显示了这样的错误

Error

我不知道,如何解决它..
请帮帮我..

更新 :
当我使用 --stacktrace 运行时
我还是不知道这是什么错误。。
The expression 'viewModelLoadingText.getValue()' cannot be inverted, so it cannot be used in a two-way binding Details: There is no inverse for method getValue, you must add an @InverseMethod annotation to the method to indicate which method should be used when using it in two-way binding expressions

最佳答案

您正在使用在此位置不正确的双向数据绑定(bind)。

更改android:text="@={viewModel.loadingText}"android:text="@{viewModel.loadingText}"
有关该问题的更多信息:当您还希望从 UI 更新数据时,使用双向数据绑定(bind)。一个案例可能是 EditText它将其文本发布到 MutableLiveData并从中设置其文本。查看 official documentation更多细节。

关于android - 找不到符号类数据绑定(bind) impl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61424074/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com