Kotlin,recyclerview适配器如何按DESC对查询结果进行排序 [英] Kotlin, recyclerview adapter how to sort results from query by DESC
问题描述
它是我的代码.我做错了什么?我想在recyclerview中显示降序结果.
its my code. What i doing wrong? I would like to display descending results in recyclerview.
TableInfo.TABLE_COLUMN_MESSAGE = "points"
override fun onBindViewHolder(p0: MojViewHolder, p1: Int) {
val wynikwynik = p0.view.textViewWynik
val wynikuser = p0.view.textView_user
val cursor = db.query(TableInfo.TABLE_NAME, null, BaseColumns._ID + "=?", arrayOf(p0.adapterPosition.plus(1).toString()), null, null, TableInfo.TABLE_COLUMN_MESSAGE +" DESC")
if (cursor.moveToFirst()){
wynikwynik.text=cursor.getString(1).toString()
wynikuser.text=cursor.getString(2).toString()
}
cursor.close()
}
推荐答案
首先,您应该分离业务逻辑的视图,我想说您不应该在recyclerView中执行db请求,最好的方法是在recyclerView中传递一组数据,这些数据就是recyclerView lList的信息,如果您在ViewHolder中发出db请求,那么您将在List的每一行中发出请求,这是一个问题.
First of all you should separate the view of your Business Logic, I want to say you shouldn't do a db request within of recyclerView, the best way is pass an val of data in your recyclerView, this data is the info for your recyclerView lList, if you make a db request inside of your ViewHolder you are making a request in every row of your List and this is a problem.
检查以下有关回收者视图工作的信息: https://developer.android.com/guide/topics/ui/layout/recyclerview
Check this information of the work of a recycler view: https://developer.android.com/guide/topics/ui/layout/recyclerview
这篇关于Kotlin,recyclerview适配器如何按DESC对查询结果进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!