【问题标题】:Using FirebaseListAdapter in Kotlin在 Kotlin 中使用 FirebaseListAdapter
【发布时间】:2018-01-17 00:20:28
【问题描述】:

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

我需要显示users 节点下可用的键(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) 以下函数都不能用 提供的参数:公共构造函数 FirebaseListAdapter(activity: Activity!, parser: ((DataSnapshot!) -> String!)!, @LayoutRes modelLayout: Int, query: Query!) 定义在 com.firebase.ui.database.FirebaseListAdapter 公共构造函数 FirebaseListAdapter(活动:活动!,解析器: SnapshotParser!,@LayoutRes modelLayout:Int,查询:查询!) 在 com.firebase.ui.database.FirebaseListAdapter public 中定义 构造函数 FirebaseListAdapter(活动:活动!, 模型类:类!,@LayoutRes 模型布局:整数,查询: 查询!)在 com.firebase.ui.database.FirebaseListAdapter 中定义

有什么办法吗?

【问题讨论】:

    标签: android firebase firebase-realtime-database kotlin firebaseui


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2017-08-02
      • 1970-01-01
      • 1970-01-01
      • 2016-06-23
      • 1970-01-01
      • 2017-07-19
      • 2016-09-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多