Monday, April 11, 2011

Set Scroll position of a listview

Requirement :

Doesn't change the scroll position even if some list items are added to Listview dynamically.

problem faced : Scroll moving to first after listitems are added.

Solution:
// save index and top position
int index = mList.getFirstVisiblePosition();
View v = mList.getChildAt(0);
int top = (v == null) ? 0 : v.getTop();

// ...

// restore
mList.setSelectionFromTop(index, top);


Ref:

http://stackoverflow.com/questions/3014089/scroll-to-a-position-in-a-listview

1 comment: