android - Reverse List Order in Array Adapter -
how modify code adds each new object top of list instead of bottom? latest object added top of list see older objects scroll lower down on list.
public class statusadapter extends arrayadapter { protected context mcontext; protected list<parseobject> mstatus; public statusadapter(context context, list<parseobject> status) { super(context, r.layout.homepage, status); mcontext = context; mstatus = status; } @override public view getview(final int position, view convertview, viewgroup parent) { viewholder holder; if (convertview == null) { convertview = layoutinflater.from(mcontext).inflate( r.layout.homepage, null); holder = new viewholder(); holder.usernamehomepage = (textview) convertview .findviewbyid(r.id.usernamehp); holder.statushomepage = (textview) convertview .findviewbyid(r.id.statushp); convertview.settag(holder); } else { holder = (viewholder) convertview.gettag(); } parseobject statusobject = (parseobject)mstatus.get(position); // title string username = statusobject.getstring("newuser") + ":"; holder.usernamehomepage.settext(username); // content string status = statusobject.getstring("newstatus"); holder.statushomepage.settext(status); return convertview; } public static class viewholder { textview usernamehomepage; textview statushomepage; } }
if want display list in reverse order newest item on top reverse list.java collection class provide reverse method reverse items in list.see below code -
collections.reverse(alist);
above code reverse list item , store result in same list.
hope you.
Comments
Post a Comment