How to sort RecyclerView item in android

前端 未结 7 1849
暖寄归人
暖寄归人 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:18

    Before passing the data to RecyclerView adapter

    data.sort(new Comparator() {
                @Override
                public int compare(Datum o1, Datum o2) {
                    return o1.get(position).getMessageId().compareTo(o2.get(position).getMessageId());
                }
            });
    

    then pass (notify) the sorted list to the adapter.

提交回复
热议问题