How do I prevent listview from scrolling to the top after using setAdapter
I have a listview that switches between a few custom lists. I press a button to toggle between the开发者_C百科 different adapters in my listview but it jumps to the top of the listview. Is there a way I can stay in the same position on the screen as I switch between lists?
don't use set adapter to update content , use notifyDatasetChanged istead
if(listView.getAdapter()==null)
listView.setAdapter(myAdapter);
else{
//update the adapter data
myAdapter.notifyDatasetChanged();
}
that should work
Use any of these 2:
1. Call getListView().setSelection(int iIndex);
2. Call getListView().smoothScrollToPosition();
Kindly let me know, if any of these works.
精彩评论