How to sort RecyclerView item in android -


i'm working on android chatting application. when called api returns me chat list sorted user_id. need serialized message_id want show last message first.here onbindviewholder method in values.

public void onbindviewholder(final myadapter_homeviewholder holder, final int position) {      holder.usernametv.settext(data.get(position).getuserinfo().getfullname());     holder.msgbodytv.settext(data.get(position).getbody());     holder.originator_id.settext(data.get(position).getuserinfo().getid().tostring());      //message id. need serialize recyclerview id.biggest id should appear first.     holder.messageid.settext(data.get(position).getid().tostring());      holder.owner_type_et.settext("1");     holder.subject_et.settext("message");  } 

in case of need see full code, https://pastebin.com/zxmq36gn

try before passing list adapter (after api call , before adapter notifydatasetchanged):

 collections.sort(data, new comparator<customdata>() {             @override             public int compare(customdata lhs, customdata rhs) {                 // -1 - less than, 1 - greater than, 0 - equal, inversed descending                 return lhs.getid() > rhs.getid() ? -1 : (lhs.customint < rhs.customint ) ? 1 : 0;             }         }); 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -