title: Android ListView row color
body: <p>I'm trying to change the row color of my listView in customAdapter. There's an array of integer that include 0 and 1, I'm trying to read from the array and change the color of rows like this:</p>
  
  <p>0 = white</p>
  
  <p>1 = yellow</p>
  
  <p>but it shows a yellow color in all rows.
  This is my CustomAdapter:</p>
  
  <pre><code>package com.example.test;
  
  import java.util.ArrayList;
  import java.util.List;
  
  import android.app.Activity;
  import android.content.Context;
  import android.graphics.Color;
  import android.util.Log;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.ArrayAdapter;
  import android.widget.ImageView;
  import android.widget.TextView;
  
  public class CustomAdapter extends ArrayAdapter&lt;RowItem&gt; {
  
  ArrayList&lt;Integer&gt; test;
  
  Context context;
  
  public CustomAdapter(Context context, int resourceId, List&lt;RowItem&gt; items) {
      super(context, resourceId, items);
      this.context = context;
  }
  
  /* private view holder class */
  private class ViewHolder {
      ImageView imageView;
      TextView txtTitle;
  }
  
  public View getView(int position, View convertView, ViewGroup parent) {
      ViewHolder holder = null;
      RowItem rowItem = getItem(position);
  
  
      SqliteHelper checkFav = new SqliteHelper(context);
      checkFav.open();
      test = checkFav.getFavForList();
      checkFav.close();
  
      LayoutInflater mInflater = (LayoutInflater) context
              .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
      if (convertView == null) {
          convertView = mInflater.inflate(R.layout.row_layout, null);
          holder = new ViewHolder();
          holder.txtTitle = (TextView) convertView.findViewById(R.id.pTxt);
  
          holder.imageView = (ImageView) convertView.findViewById(R.id.icon);
          convertView.setTag(holder);
  
  
      } else
  
  
          holder = (ViewHolder) convertView.getTag();
  
                      int color0 = Color.YELLOW;
          int colorDefault = Color.WHITE;
  
          switch (test.get(position)){
          case 0:
              convertView.setBackgroundColor(colorDefault);
              break;
          case 1:
              convertView.setBackgroundColor(color0);
          }       
              holder.txtTitle.setText(rowItem.getTitle());
  
      holder.imageView.setImageResource(rowItem.getImageId());
  
      return convertView;
  }
  
  }
  </code></pre>
  
  <p>And this is my row_layout.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="horizontal" &gt;
  
      &lt;ImageView
          android:id="@+id/icon"
          android:layout_width="50dp"
          android:layout_height="50dp"
          android:layout_marginBottom="5dp"
          android:layout_marginLeft="5dp"
          android:layout_marginRight="5dp"
          android:layout_marginTop="5dp"
          android:src="@drawable/active_icon" /&gt;
  
      &lt;TextView
          android:id="@+id/pTxt"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:textSize="20sp"
          android:gravity="right"/&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Thanks in advance.</p>