How do I modify this code so that it adds each new object to the top of the list instead of the bottom? I would like the latest object to be added to the very top of the list so you see older objects as you scroll lower down on the 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 you want to display list in reverse order newest item on top then just reverse your list.Java collection class provide a reverse method which reverse all items in a list.See below code -
Collections.reverse(aList);
Above code reverse list item and store result in same list.
Hope it will help you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With