Retaining position in ListView after calling notifyDataSetChanged
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 28/09/2017:
The API has changed quite a bit since 2015. It is similar, but now it would 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);
The situation:
When you set an adapter to your listview, it refreshes its state. So, normally scrolls up automatically.
The solution:
Assign an adapter to listview if it has not any, else only update the dataset of the assigned adapter, not re-set it to your listview.
A detailed tutorial is explained at the following link;
Android ListView: Maintain your scroll position when you refresh
Good Luck!