我如何在一个recyclerView (Kotlin)中使用多行



我想在我的应用程序中使用基于Firestore数据库的用户不同的行。所以我想分类用户的点数评级(长)。所以会有多个等级和等级号。例如,如果评级是100,我想显示红色行与女士排名。我怎么能做到呢?谢谢大家)

这是我的应用程序屏幕

我的活动代码

private fun get_information() {
database.collection("ProfPic").orderBy("Username",
Query.Direction.DESCENDING).addSnapshotListener { snaphot, exception ->
if (exception != null) {
Toast.makeText(this, exception.localizedMessage, Toast.LENGTH_LONG).show()
} else {
if (snaphot != null) {
if (!snaphot.isEmpty) {
val documents = snaphot.documents
posts_list.clear()
for (document in documents) {
val username = document.get("Username") as String
val fullname = document.get("Fullname") as String
val rank = document.get("Rank") as String
val rating = document.get("Rating") as Long

val download_post = publiks(username, fullname, rating, rank)
posts_list.add(download_post)
}
}
recyclerViewAdapter.notifyDataSetChanged()

My Adapter Codes

class new_adapter(var post_list: List<publiks>, clickListener: Feed) : RecyclerView.Adapter<new_adapter.PostHolder>() {
private var clickListener: Feed = clickListener;


class PostHolder(itemView: View) :
RecyclerView.ViewHolder(itemView) {

init {
itemView.setOnClickListener {

}
}
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PostHolder {
val inflater = LayoutInflater.from(parent.context)
val view = inflater.inflate(R.layout.rec_row, parent, false)
return PostHolder(view)
}
override fun onBindViewHolder(holder: PostHolder, position: Int) {
var userModel = post_list.get(position)

holder.itemView.username.text = post_list[position].username
holder.itemView.fullname.text = post_list[position].fullname
holder.itemView.rating.text = post_list[position].rating.toString()
holder.itemView.idrank.text = post_list[position].rank




}

您可以在onBindViewHolder函数中编写此代码

override fun onBindViewHolder(holder: PostHolder, position: Int) {
var userModel = post_list.get(position)
if (userModel.rating == 100) {
holder.itemView.setBackgroundColor(R.color.black)
}
holder.itemView.username.text = userModel.username
holder.itemView.fullname.text = userModel.fullname
holder.itemView.rating.text = userModel.rating.toString()
holder.itemView.idrank.text = userModel.rank
}

相关内容

  • 没有找到相关文章

最新更新