Jay Askren
Jay Askren

Reputation: 10444

How do I programmatically select an item in a listview in Android

I am displaying a radio schedule in a List View and would like to highlight the currently playing program. I also want to allow the user to click on any program and get more details for the program. I have tried the following:

radioView.setSelection(adapter.getCurrentProgramIndex());
radioView.setSelected(true);

This does scroll the list down to the selection which is good, but it does not highlight the selection. I understand this is because the device is not in touch mode, but how then would I go about highlighting the current program?

Upvotes: 0

Views: 3567

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006594

how then would I go about highlighting the current program?

Change something in that list row. For example, perhaps you have an icon you can switch to be a "playing" icon, or have an icon that is formerly INVISIBLE become VISIBLE, or something.

Bear in mind that you will need to have these smarts in your row binding code, so that if the user scrolls, you correct undo and redo that setting -- otherwise, row recycling will make it appear that other programs are playing.

Upvotes: 2

Related Questions