Я делаю код, но не правильную сортировку, я хочу сортировать для ScoreVaule (число) для LeaderBoard Я сделал сортировку по firebase orderChild ("ScoreVaule"), но результат не очень хороший
fun leaderboard22(){
val RV4 = findViewById(R.id.recyclerView3) as RecyclerView
RV4.layoutManager = LinearLayoutManager(this, LinearLayout.VERTICAL, false)
val Recycler33 = ArrayList<ListCellForLeaderBoard>()
ref.child("Score").orderByChild("scoreVaule").limitToFirst(200).addValueEventListener(object : ValueEventListener {
override fun onCancelled(p0: DatabaseError) {
}
override fun onDataChange(dataSnapshot: DataSnapshot) {
try{
val td = dataSnapshot.value as HashMap<String,Any>
Recycler33.clear()
for (q2 in td.keys){
val data = td[q2] as HashMap<String,Any>
Recycler33.add(ListCellForLeaderBoard(
data["name"] as String?,
data["profileImageurl"] as String?,
data["scoreVaule"] as Long?
))
}
val adapter3 = RecyclerViewAdapterLeaderBoard(Recycler33)
RV4.adapter = adapter3
}catch (ex:Exception){
println("It is not found88888888888888")
}
}})
}
и этоэто класс Адаптер
class RecyclerViewAdapterLeaderBoard(val listAdapter:ArrayList<ListCellForLeaderBoard>) : RecyclerView.Adapter<RecyclerViewAdapterLeaderBoard.ViewHolder>(){
override fun onCreateViewHolder(p0: ViewGroup, p1: Int): ViewHolder {
val v = LayoutInflater.from(p0.context).inflate(R.layout.list_view_leaderboard, p0, false)
return ViewHolder(v)
}
override fun getItemCount(): Int {
return listAdapter.size
}
override fun onBindViewHolder(p0: ViewHolder, p1: Int) {
val recyclerView1 = listAdapter[p1]
p0.name.text = recyclerView1.name
p0.scoreVaule.text = recyclerView1.scoreVaule.toString()
Picasso.get().load(recyclerView1.profileImageurl).into(p0.imageView)
}
class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), View.OnClickListener{
val all = itemView.findViewById(R.id.all) as ConstraintLayout
val name = itemView.findViewById(R.id.text_111) as TextView
val noNum = itemView.findViewById(R.id.text_222) as TextView
val scoreVaule = itemView.findViewById(R.id.text_333) as TextView
@SuppressLint("WrongViewCast")
val imageView = itemView.findViewById(R.id.image3) as ImageView
var itemview = itemView
var listener:OnClick? = null
init {
this.listener = listener
itemview.setOnClickListener(this)
}
override fun onClick(v: View?) {
listener?.onClick(v!!, adapterPosition)
}
}
}
и это фотографии
оценка базы данных и результат не отсортирован по ScoreVaule
Этот результат не отсортирован по ScoreVaule