Could this be what you want?
// save index and top position int index = mList.getFirstVisiblePosition(); View v = mList.getChildAt(0); int top = (v == null) ? 0 : v.getTop(); // notify dataset changed or re-assign adapter here // restore the position of listview mList.setSelectionFromTop(index, top);
EDIT 09/28/2017:
The API has changed quite a bit since 2015. This is similar, but now it will be:
// save index and top position int index = mList.FirstVisiblePosition; //This changed View v = mList.getChildAt(0); int top = (v == null) ? 0 : v.Top; //this changed // notify dataset changed or re-assign adapter here // restore the position of listview mList.setSelectionFromTop(index, top);
iCantSeeSharp Nov 26 2018-11-11T00: 00Z
source share