How to sort RecyclerView item in android

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

    try this before passing your list to the adapter (after API call and before adapter notifydatasetchanged):

     Collections.sort(data, new Comparator() {
                @Override
                public int compare(CustomData lhs, CustomData rhs) {
                    // -1 - less than, 1 - greater than, 0 - equal, all inversed for descending
                    return lhs.getId() > rhs.getId() ? -1 : (lhs.customInt < rhs.customInt ) ? 1 : 0;
                }
            });
    

提交回复
热议问题