sorting - Android automatic sort list of model when new item is added -


hi have , android app using recycleview. have model class topstory variable time (data long value). new item added list of topstory (topstories) json response server. want update recycle view add new item sort items time (i.e: newest appear first (by time)).

this model

public class topstory {     private int id;     private string title;     private string author;     private int score;     private jsonarray kids;     private long time;     private string url;      public topstory() {     }      public topstory(int id, string title, string author, int point, long time,string url) {         this.id = id;         this.title = title;         this.author = author;         this.score = point;         this.time = time;         this.url = url;     } 

and response contain item add list of topstory (topstories)

private void gettopstorydetail(requestqueue requestqueue, string topstoryurl, final progressbar progressbar) {          progressbar.setvisibility(view.visible);         customjsonobjectrequest jsonobjectrequest = new customjsonobjectrequest(request.method.get,topstoryurl,null,                 new response.listener<jsonobject>() {                     @override                     public void onresponse(jsonobject respond) {                         progressbar.setvisibility(view.gone);                         topstory topstory = topstory.fromjson(respond);                         topstories.add(topstory);                         adapter.notifydatasetchanged();                      }                 },                 new response.errorlistener() {                     @override                     public void onerrorresponse(volleyerror error) {                         toast.maketext(getapplicationcontext(), error.getmessage(), toast.length_long).show();                         progressbar.setvisibility(view.gone);                     }                 });         //adding request queue         requestqueue.add(jsonobjectrequest);     } 

how modify response code each time new item add. list topstories sorted time , recycleview display item order (bytime)

any appreciated. thanks


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -