I have a simple ListView
with some items that have setChoiceMode
set to ListView.CHOICE_MODE_SINGLE
, which means when I touch an item, it is highlighted. This way the user can see what menu choice (the ListView
is a menu) was chosen:
listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
However, I want to change that selection from code (not by touching). I tried this:
listView.setSelection(0);
but it seems to have no effect. Probably because selection and activation are different concepts. There is no setActivated(int)
method available.
you can select item with following code:
listView.setItemChecked(position, true);
Using this method worked for me
listView.performItemClick(listView, position, listView.getItemIdAtPosition(position));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With