Android : View background color can not work with selector?

on Sunday, August 10, 2014


I am working on an android application , and I have a lot of items to display by the ListView:



<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@android:id/list"
android:layout_gravity="right|center_vertical"
android:listSelector="@drawable/bg_selector"/>


bg_selector.xml:



<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="#8F136fb8"/>
</selector>


And I want each item have a different background color, and I set them in the getView method of the adapter:



@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder;
.....
Color color=generateColor();
viewHolder.textView.setBackgroundColor(color);
return convertView;
}


However I found that that once I select an item, there is no effect responded to the user event I set the selector to the ListViewenter image description here


0 comments:

Post a Comment