Programmatically scroll to a specific position in an Android ListView

Maxime  picture Maxime · Sep 26, 2011 · Viewed 168.9k times · Source

How can I programmatically scroll to a specific position in a ListView?

For example, I have a String[] {A,B,C,D....}, and I need to set the top visible item of the ListView to the index 21 of my String[].

Answer

HandlerExploit picture HandlerExploit · Sep 26, 2011

For a direct scroll:

getListView().setSelection(21);

For a smooth scroll:

getListView().smoothScrollToPosition(21);