android-fragments - 如何在 Kotlin 中使用 AndroidAnnotation @FragmentArg?

标签 android-fragments kotlin android-annotations

如何使用 @FragmentArg来自 AndroidAnnotationsKotlin 内分段?

@EFragment(R.layout.debug_empty_fragment)
open class EmptyFragment : Fragment(){

    @FragmentArg("debugIndex")
    var debugIndex:Int = 0
}

这给了我以下 gradle 错误:
error: org.androidannotations.annotations.FragmentArg cannot be used on a private element

我尝试制作 debugIndex open (公共(public)),但它不起作用。有任何想法吗?这甚至可能吗?

我正在使用 Android Annotations 4.3.1 和 kotlin 1.1.2-5

最佳答案

好的,@JvmField是你的 friend 。 (further information)

Instructs the Kotlin compiler not to generate getters/setters for this property and expose it as a field.



所以@FragmentArg应该是这样的
@JvmField
@FragmentArg("debugIndex")
var debugIndex:Int = 0

关于android-fragments - 如何在 Kotlin 中使用 AndroidAnnotation @FragmentArg?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44718209/

相关文章:

android - 如何将点击事件从 fragment 传递到容器 Activity ?

kotlin - 如何在不调用 kotlin 的 setter 和 getter 的情况下访问变量

arrays - Kotlin 使用另一个数组初始化一个数组

java - 在 kotlin 项目上使用 java 文件

java - fragment 事务空指针

Android ViewPager 获取当前 View

android - annotationprocessor 和 apt configure 等效

android - AndroidAnnotations 中的 NetworkOnMainThreadException

java - 有什么办法可以用这种方式替换这段代码吗?

Android:从 Activity 输入数据后刷新 ViewPager fragment 内容