I use ListView to show my items.
The matter is when I want to update or delete some items, I have to clear ArrayList assigned to ListViewAdapter and use notifyDataSetChanged
. This causes ListView to scroll to the bottom. How can I prevent to scroll ListView in this situation?
the ListView is a list of chat messages and I want to update the list every 15 seconds. When a user is reading messages and scrolling up, after refreshing the ListView, it scrolls to the bottom.
I see this.
Asked
Active
Viewed 137 times
0

Phantômaxx
- 37,901
- 21
- 84
- 115

Hajitsu
- 764
- 17
- 49
-
Most importantly, why are you still using ListView? – Ali Bdeir Aug 27 '19 at 15:33
-
1So help me to improve me. What widget I can use? – Hajitsu Aug 27 '19 at 15:37
-
3You should be using a `RecyclerView`. [More on that here](https://developer.android.com/guide/topics/ui/layout/recyclerview) – Ali Bdeir Aug 27 '19 at 15:39
-
1Are you using firebase ? If yes i would like to suggest you to use Firebase Recycleradapter . – Muntasir Aonik Aug 27 '19 at 15:53
-
1Definitely don't use a ListView. Use a `RecyclerView` with a `ListAdapter
` and instead of use `notifyDataSetChanged()` pass a new list and let the Listadapter calculate the diff using `DiffUtil.Callback` – Martin Marconcini Aug 27 '19 at 16:58