Add new items to top of list view on Android?

Hmm, well, if I was going to try this, I’d do something like the following:

List items = new ArrayList();

//some fictitious objectList where we're populating data
for(Object obj : objectList) {
    items.add(0, obj);
    listAdapter.notifyDataSetChanged();
}

listView.post(new Runnable() {
    @Override
    public void run() {
        listView.smoothScrollToPosition(0);
    }
}

I don’t know for certain that this will work, but it seems logical. Basically, just make sure to add the item at the beginning of the list (position 0), refresh the list adapter, and scroll to position (0, 0).

Leave a Comment