I have this list:
<ListView
android:id="@+id/contactsView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/searchButton"
android:divider="@color/DarkGoldenrod"
android:dividerHeight="0.1dp"
android:listSelector="@drawable/list_selector"
android:choiceMode="singleChoice" />
This is the code for list_selector:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@android:drawable/myRedColor" android:state_pressed="true"/>
<item android:drawable="@android:drawable/myBlueColor" android:state_selected="true"/>
<item android:drawable="@android:drawable/myGreenColor"/>
</selector>
In my main activity class, I set the following:
contactsView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
arg1.setSelected(true);
selectedContactIndex = (int) arg3;
}
});
contactsView- this is a list, and I confirmed that it is selected, but the color does not remain. I click on it, and it changes, and then comes back. Any idea why?
source
share