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
Collections.sort(response.body(), new Comparator() {
@Override
public int compare(All_posts lhs, All_posts rhs) {
if(lhs.getId() > rhs.getId()) {
return -1;
} else {
return 1;
}
}
});
"response.body" is the arraylist I got from json, this is what I pass to the recycler view adapter,
"All_posts" is the "Model" class, the one which contains only fields;
And getId is the value I want comparison to take place on it, it's from my model class,
I wrote this before I set my adapter to my recycler view.
and after I set my adpater to my recyclerView, I wrote recyclerView.getAdapter().notifyDataSetChanged();