I have a ListView with huge amount of data.But when i go to next page on ListView Item Click and come back to ListView. I want the list to be scrolled to the same point that it was previously.Can someone help to achieve this.
I tried this code.List to be scrolled to the same point but immediately come to the first position.
private void populateList() {
descArray.clear();
List<All_Post> allDesc = dbhelper.getAllDescriptions();
for (All_Post all_Post : allDesc)
{
descArray.add(all_Post);
}
if (adapter == null)
{
adapter = new AllPostAdapter(this, R.layout.allpostlist, descArray);
listView.setAdapter(adapter);
}
else if (adapter != null) {
adapter.notifyDataSetChanged();
adapter = new AllPostAdapter(this, R.layout.allpostlist, descArray);
listView.setAdapter(adapter);
//int firstPosition = listView.getFirstVisiblePosition();
//listView.setSelection(firstPosition);
int index = listView.getFirstVisiblePosition();
View v = listView.getChildAt(0);
int top = (v == null) ? 0 : (v.getTop() - listView.getPaddingTop());
listView.setSelectionFromTop(index, top);
}
}