How to sort RecyclerView item in android

前端 未结 7 1874
暖寄归人
暖寄归人 2021-01-01 11:29

I\'m working on a android chatting application. When I called my api it returns me the chat list sorted by a user_id. But what I need to do is serialized by

7条回答
  •  无人及你
    2021-01-01 12:02

    in Kotlin use like this after loading data in array:

    myItems.sortWith(Comparator { lhs, rhs ->
                // -1 - less than, 1 - greater than, 0 - equal, all inversed for descending
                if (lhs.name > rhs.name) -1 else if (lhs.id < rhs.id) 1 else 0
            })
    

    After that apply:

    myItemAdapter.notifyDataSetChanged()
    

提交回复
热议问题