android - 在 Kotlin 中使用 FirebaseListAdapter

标签 android firebase firebase-realtime-database kotlin firebaseui

我正在尝试实现一个带有 FirebaseListAdapterListView。我需要在适配器内显示一个字符串列表,所以我使用 String 作为通用。 Firebase 数据库的结构是这样的:

enter image description here

我需要显示 users 节点下可用的 key (102127...、102133... 等),因此我使用此代码创建适配器:

val ref = db.getReference(MATCHES_REF).child(match).child(USERS_REF)
val adapter = object : FirebaseListAdapter<String>(this, String::class.java, R.layout.cell_friends, ref) {
    override fun populateView(view: View, s: String, i: Int) {
        val text = view.findViewById(R.id.text_view) as TextView
        text.text = s
    }
}
listView?.adapter = adapter

这是 Android Studio 中显示的错误:

Error:(50, 32) None of the following functions can be called with the arguments supplied: public constructor FirebaseListAdapter(activity: Activity!, parser: ((DataSnapshot!) -> String!)!, @LayoutRes modelLayout: Int, query: Query!) defined in com.firebase.ui.database.FirebaseListAdapter public constructor FirebaseListAdapter(activity: Activity!, parser: SnapshotParser!, @LayoutRes modelLayout: Int, query: Query!) defined in com.firebase.ui.database.FirebaseListAdapter public constructor FirebaseListAdapter(activity: Activity!, modelClass: Class!, @LayoutRes modelLayout: Int, query: Query!) defined in com.firebase.ui.database.FirebaseListAdapter

有什么解决办法吗?

最佳答案

已解决,FirebaseListAdaptwer 构造函数 (this) 的第一个参数不是 Activity 类型。

关于android - 在 Kotlin 中使用 FirebaseListAdapter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45585102/

相关文章:

android - ContentResolver.setSyncAutomatically(Account account,String authority,boolean sync)它的第二个参数是什么意思呢?

javascript - Firebase - 仅获取具有指定键的元素

ios - 拍摄数据快照时出现 Firebase NSNull 异常

javascript - 将 Firebase 中的数据显示到表中时出现问题?

java - 我可以执行类似语言命令的字符串吗?

java - 如何使用 jsoup 文档将 child 添加到子节点

java - 动画仅在第一次单击按钮时移动

firebase - 定价 : is multiple field changes in a firestore document cache seen as a single write when device is online?

arrays - 如何设计存储数组的简单 Firebase 数据库?

java - 无法将 Firebase 数据库中存储的图像(静态)提取到我的应用程序中