Losing current selection when calling adapter.notifyDataSetChanged()
I have expanded list view, which contains 15 items, when i reache开发者_JS百科s to the bottom i load 15 more. When i get the 15 more, i called adapter.notifyDataSetChanged() , then list moves to the top, so lost my current selection. I wanted, list should add more but it should goes to bottom, my selection stat should not be changed, like gmail app. They added new items at bottom silently. How to achieve this?
You can set the selectionMode
of your ListView
to ListView.CHOICE_MODE_SINGLE
.
listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
By default ListView
has a CHOICE_MODE_NONE
. Setting it to either CHOICE_MODE_SINGLE
or CHOICE_MODE_MULTIPLE
will keep your selected item(s)'s state.
You can read more on this topic in Android Developers' article about Touch Mode
精彩评论