Is there a way to prevent the listview from scrolling to its top position when its adapter's data is changed?

前端 未结 4 1152
無奈伤痛
無奈伤痛 2020-12-09 03:43

I\'m having a bit of trouble preserving the scroll position of a list view when changing it\'s adapter\'s data.

What I\'m currently doing is to create a custom Array

4条回答
  •  盖世英雄少女心
    2020-12-09 04:19

    There is one more use-case I came across recently (Android 8.1) - caused by bug in Android code. If I use mouse-wheel to scroll list view - consecutive adapter.notifyDataSetChanged() resets scroll position to zero. Use this workaround until bug gets fixed in Android

            listView.onTouchModeChanged(true); // workaround
            adapter.notifyDataSetChanged();
    

    More details is here: https://issuetracker.google.com/u/1/issues/130103876

提交回复
热议问题