gpt4 book ai didi

android - EpoxyModels 在 Android 的功能模块/库项目中不起作用

转载 作者:行者123 更新时间:2023-12-05 00:09:55 26 4
gpt4 key购买 nike

使用 Android 应用程序的内部功能模块时,EpoxyModels 未编译。

@EpoxyModelClass(layout = R.layout.layout_foo) //an annotation argument must be a compile-time constant here
abstract class FooModel : EpoxyModelWithHolder<FooModel.FooHolder>()
{
...
...

class FooHolder : BaseEpoxyHolder()
{
val textViewTitle: TextView by bind((R.id.textViewTitle))
//bind is the method borrowed from [here](https://github.com/airbnb/epoxy/blob/963ef0fd850bd379da7b0be6a2ada25d01ae0ee7/kotlinsample/src/main/java/com/airbnb/epoxy/kotlinsample/helpers/KotlinEpoxyHolder.kt#L20)
}
}

上面的代码提示 layout = R.layout.layout_foo 行的“注释参数必须是编译时常量”。

再次根据文档看起来,butterknife 需要用于库项目(功能模块在某种程度上是一种库项目),它将基于 this 生成 R2 类。

下面是使用 Butterknife 修改后的代码,我也认为它太过分了。不确定,为什么我不能只执行 findviewbyId。

ModelClass(layout = R2.layout.layout_foo)
abstract class FooModel : EpoxyModelWithHolder<FooModel.FooHolder>() {

@EpoxyAttribute
lateinit var fooDto: Foo

override fun bind(holder: FooHolder) {
holder.textViewTitle.text = fooDto.title
}

class FooHolder : BaseEpoxyHolder() {
@BindView(R2.id.textViewTitle) lateinit var textViewTitle: TextView
}
}

下面是带有 butterknife 的 viewholder 的错误

kotlin.UninitializedPropertyAccessException: lateinit property textViewTitle has not been initialized

最佳答案

正如所说:

https://github.com/airbnb/epoxy/issues/819#issuecomment-576728923

在库项目上使用该注释存在问题。

目前你可以使用:

@EpoxyModelClass
abstract class MyModel : EpoxyModelWithHolder<MyHolder>() {

override fun getDefaultLayout(): Int {
return R.layout.my_layout
}
}

关于android - EpoxyModels 在 Android 的功能模块/库项目中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59843745/

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