Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/348.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 交替Android ListView颜色不起作用_Java_Android Widget - Fatal编程技术网

Java 交替Android ListView颜色不起作用

Java 交替Android ListView颜色不起作用,java,android-widget,Java,Android Widget,我已经扩展了SimpleAdapter以在我的ListView中设置交替颜色。我可以确认getView正在被调用。然而,屏幕上从未出现颜色变化。我在任何地方都尝试过android:cacheColorHint=“#00000000”,但这不起作用。有什么想法吗 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/and

我已经扩展了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>

公共类mysimpledapter扩展了simpledapter
{
私有int[]颜色=新int[]{0xEEE9E9,0xCDC9C9};
public MySimpleAdapter(上下文上下文、列表项、int资源、字符串[]from、int[]to)
{
超级(上下文、项目、资源、发件人、收件人);
}
公共视图getView(int位置、视图转换视图、视图组父视图)
{  
视图=super.getView(位置、转换视图、父级);
int colorPos=位置%colors.length;
视图.setBackgroundColor(颜色[colorPos]);
返回视图;
} 
}

看起来您正在使用alpha=0设置颜色;尝试添加alpha组件(例如,使用0xFFEE9E9E代替0xEE9E9E)。您正在设置完全透明的颜色

    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;  

    } 

}