setSelected() works buggy with ListView
For API 11+:
1) Set list view to single choice:
<ListView
android:choiceMode="singleChoice" />
2) Set the background of the root element of your item layout to your selector:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/selector">
3) Change android:state_selected
to android:state_activated
:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/list_item_selected_color"
android:state_activated="true"/>
<item android:drawable="@color/list_item_default_color"/>
</selector>
4) Highlight item using listView.setItemChecked(index, true);
Note: To make it clear regarding view's states, specially state_activated
you can check this post; it is interesting.
How to set selected item of ListView without scrolling the view [Android]
I think it's hardcoded and thus not possible without scrolling
Related Topics
Changing Text Color of Menu Item in Navigation Drawer
Android: Running a Background Task Using Alarmmanager
Android Exporting to CSV and Sending as Email Attachment
Smoothscrolltopositionfromtop() Is Not Always Working Like It Should
Inserting Contacts in Android 2.2
Android Studio Build Fails with "Task '' Not Found in Root Project 'Myproject'."
Taking Screenshot Programmatically Doesnt Capture the Contents of Surfaceview
Fragment-Fragment Communication in Android
Android Studio: Application Installation Failed
Differencebetween Src and Background of Imageview
Video Streaming Using Rtsp: Android
Load Large Images with Picasso and Custom Transform Object
Bitmap, Bitmap.Recycle(), Weakreferences, and Garbage Collection
Onclicklistener - X,Y Location of Event
Set Permission for Getting User's Email Id from Facebook Login