Other solution (mostly in XML)
1) set the choiceMode
of the ListView
to singleChoice
<ListView
android:choiceMode="singleChoice"
.../>
2) Items of the list must be a Checkable View and use a Color State List as Background
eg: album_item.xml
<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/list_selector"
.../>
3) the background Color State (list_selector.xml
) defines the highlight color
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/green" android:state_checked="true"/>
<item android:drawable="@color/green" android:state_pressed="true"/>
</selector>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…