我正在努力解决这个错误。我正在尝试使用FirebaseRecyclerAdapter,在构建选项时,我在FirebaseRecRecyclerOptions中的SetQuery中遇到了这个错误。有线索吗?非常感谢。
None of the following functions can be called with the arguments supplied:
public open fun setQuery(p0: Query, p1: SnapshotParser<Tuto!>):
FirebaseRecyclerOptions.Builder<Tuto!> defined in
com.firebase.ui.database.FirebaseRecyclerOptions.Builder
public open fun setQuery(p0: Query, p1: Class<Tuto!>): FirebaseRecyclerOptions.Builder<Tuto!>
defined in com.firebase.ui.database.FirebaseRecyclerOptions.Builder
这是我的代码:
firebaseDB = FirebaseFirestore.getInstance()
firebaseStorage = FirebaseStorage.getInstance()
val tutosRef = firebaseDB!!.collection("tutos")
val tutoQuery = tutosRef.limitToLast(50);
val options = FirebaseRecyclerOptions.Builder<Tuto>()
.setQuery(tutoQuery,Tuto::class.java)
.setLifecycleOwner(this)
.build()
val adapter = object : FirebaseRecyclerAdapter<Tuto, TutoAdapter>(options) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TutoAdapter {
return TutoAdapter(LayoutInflater.from(parent.context)
.inflate(R.layout.tuto_holder, parent, false))
}
override fun onBindViewHolder(holder: TutoAdapter, position: Int, model: Tuto) {
holder.bind(model)
}
}
还有我的图图族:
class Tuto{
var alias: String? = null
var title: String? = null
var description: String? = null
var owner: String? = null
var date_creation: Timestamp? = null
var steps_list: List<String>? = null
var steps_number: Int? = null
override fun toString(): String {
val result: String
result = """
${date_creation.toString()}
$description
$owner
$steps_number
$title
""".trimIndent()
return result
}
}
Firebase提供两个数据库,Firestore和Realtime Database。它们是完全不同的数据库,具有不同的API。您的代码正在查询Firestore:
firebaseDB = FirebaseFirestore.getInstance()
val tutosRef = firebaseDB!!.collection("tutos")
但您正在使用实时数据库的Firebase UI:
val options = FirebaseRecyclerOptions.Builder<Tuto>()
.setQuery(tutoQuery,Tuto::class.java)
.setLifecycleOwner(this)
.build()
val adapter = object : FirebaseRecyclerAdapter<Tuto, TutoAdapter>(options) {...}
您将需要按照Firestore的Firebase UI的说明进行操作,其中包括使用FirestoreRecyclerAdapter
。