i have a ListView on a ListFragment that use SimpleCursorAdapter to generate my list. i wanted to highlight selected item in my ListView, i’ve tried :
v.setBackgroundResource(R.color.listselect_light_blue);
in onListItemClick but it works odd and it selects two row when i click one of items and i want it to be single , i also set Choice Mode
<ListView android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:choiceMode="singleChoice"
android:cacheColorHint="#00000000"
/>
i’ve tried ListSelector but when i click on an item it doesn’t highlight until i scroll the list and it turn highlighted.
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
getListView().setSelector(R.drawable.listview_selector);
}
and :
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="false" android:drawable="@color/listselect_light_blue" />
</selector>
any help would be appreciated
Try this way if you want to highlight selected item in
Listview.This works for me.
First set Adapter in Listfragment before use setSelector(..).
fragment_listselector.xml
when onItemClick(..) is called put this code.