Android:To set an item as selected when the ListView opens?

kiki picture kiki · Oct 8, 2010 · Viewed 67.4k times · Source

An activity has a Button and a ListView. Initially, only the Button is visible. When the button is pressed, the ListView is displayed. When displayed, is it possible for me to show one particular item as selected/focussed?

A use case could be that suppose it is a list of language settings and when the list opens, the currently selected language must be shown as highlighted.

If I know the index of the item, how to set it as focused on display?

Answer

Piotr L. picture Piotr L. · Jun 18, 2013

I post my solution, because google still doesn't know the answer.

getListView().setItemChecked(selectedGroupIndex, true);