I have extended SimpleAdapter to set alternating colors in my ListView. I can confirm the getView is getting called. However, the color change never ocurrs on the screen. I have tried android:cacheColorHint="#00000000" everywhere but that doesn't work. Any ideas?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Spinner android:id="@+id/summary_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:prompt="@string/summary_spinner_prompt"/>
<Button android:id="@+id/summary_button_show"
android:text="@string/summary_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5sp"
android:layout_toRightOf="@id/summary_spinner"/>
<TextView android:id="@+id/summary_list_header1"
android:text="@string/summary_age"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/summary_spinner"
android:background="#8B8989"
android:textColor="#000000"/>
<TextView android:id="@+id/summary_list_header2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/summary_spinner"
android:layout_alignParentRight="true"
android:background="#8B8989"
android:textColor="#000000"/>
<ListView android:id="@id/android:list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/summary_list_header1"
android:cacheColorHint="#00000000"
android:visibility="visible"/>
</RelativeLayout>
public class MySimpleAdapter extends SimpleAdapter
{
private int[] colors = new int[] { 0xEEE9E9, 0xCDC9C9 };
public MySimpleAdapter(Context context, List<HashMap<String, String>> items, int resource, String[] from, int[] to)
{
super(context, items, resource, from, to);
}
public View getView(int position, View convertView, ViewGroup parent)
{
View view = super.getView(position, convertView, parent);
int colorPos = position % colors.开发者_如何学JAVAlength;
view.setBackgroundColor(colors[colorPos]);
return view;
}
}
Looks like you're setting colors with alpha = 0; try adding the alpha component (e.g. instead of 0xEE9E9E use 0xFFEE9E9E). You are setting fully transparent colors...
精彩评论