Переменные цвета Android ListView не работают - PullRequest
2 голосов
/ 26 февраля 2011

Я расширил SimpleAdapter, чтобы установить чередующиеся цвета в моем ListView.Я могу подтвердить, что getView вызывается.Однако изменение цвета никогда не происходит на экране.Я пробовал Android: cacheColorHint = "# 00000000" везде, но это не работает.Есть идеи?

<?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.length;  

        view.setBackgroundColor(colors[colorPos]);  

        return view;  

    } 

}

1 Ответ

1 голос
/ 08 августа 2011

Похоже, вы устанавливаете цвета с альфа = 0;попробуйте добавить альфа-компонент (например, вместо 0xEE9E9E используйте 0xFFEE9E9E).Вы устанавливаете полностью прозрачные цвета ...

...