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.set
Try this way if you want to highlight selected item in Listview
.
This works for me.
First set Adapter in Listfragment before use setSelector(..).
setListAdapter(mAdapter);
getListView().setSelector(R.drawable.fragment_listselector);
fragment_listselector.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:exitFadeDuration="@android:integer/config_mediumAnimTime">
<item android:state_activated="true"
android:drawable="@drawable/list_item_active_pattern" />
<item android:drawable="@drawable/list_bg_pattern" />
</selector>
when onItemClick(..) is called put this code.
@Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id)
{
getListView().setItemChecked(position, true);
getListView().setSelection(position);
getListView().setSelected(true);
}