1

When a button is clicked, I would like the app to smoothly scroll to the bottom of a listview. Currently this is my implementation (kotlin)

listview.post { listview.smoothScrollToPosition(adapter.count - 1) }

However, this does not always work properly: Some list items contain some expandable parts (i.e. view whose visibility can be VISIBLE or GONE), which initially are hidden. When these parts are expanded however, the function sometimes does not scroll to the end, but to a position before the end.

How can I reliably scroll to the end of the listview?

Lior Bar-On
  • 10,784
  • 5
  • 34
  • 46
IARI
  • 1,217
  • 1
  • 18
  • 35

2 Answers2

0

Try following. it will solve your problem, i tried it and it works great.

listView.post(new Runnable(){
             public void run() {
             listView.setSelection(listView.getCount() - 1);
    }});
sam chaudhari
  • 756
  • 1
  • 12
  • 24
0

add android:transcriptMode="alwaysScroll" to the ListView block in xml

Abdelaziz refaat
  • 157
  • 1
  • 12