3

Here and in some other places I found a proposed solution for the problem of keeping the scroll position while adding items to the top of a list.

I tested it and the result is that the list scrolls and then the original position is restored but the user can see the list jumping.

Another problem with this approach is that if I add the items very quickly it does not work. The reason is that the new cursor can have more than one new item because some previous cursors did not manage to be used.

Is there a better solution?

Community
  • 1
  • 1
kingston
  • 11,053
  • 14
  • 62
  • 116

1 Answers1

0

Can try this

listPos = getListView().getFirstVisiblePosition();
int newPos = listPos + (customAdapter.getCount() - oldListSize);
getListView().setSelectionFromTop(newPos, 0)
user1634451
  • 5,133
  • 6
  • 30
  • 43