Android, changing background of list in array adapter?
<p>In my application i have list which i inflate it with array adapter. every thing is OK and i have my result in the list. </p>

<p>I like to change background color of list (even rows red for example and odd rows green).</p>

<p>This is xml of my rows:</p>

<pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    &gt;
    &lt;RelativeLayout
        android:id="@+id/rllist"
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="15dip"
        android:layout_marginBottom="15dip"
        &gt;
        &lt;TextView
            android:id="@+id/outstanding_contractdate"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#ffffff"
            android:textSize="15sp" /&gt;
        &lt;TextView
            android:id="@+id/outstanding_contractno"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/outstanding_contractdate"
            android:paddingLeft="20dip"
            android:textColor="#ffffff"
            android:textSize="15sp" /&gt;
        &lt;TextView
            android:id="@+id/outstanding_contractamount"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:textSize="15sp" /&gt;
    &lt;/RelativeLayout&gt;   
&lt;/LinearLayout&gt;
</code></pre>

<p>I have written following codes:</p>

<pre><code>static class ViewHolder {
    RelativeLayout rlList;
    TextView tvContDate;
    TextView tvContNo;
    TextView tvContAmount;
}
</code></pre>

<p>and in Array Adapter I have this one:</p>

<pre><code>public View getView(int position, View convertView, ViewGroup parent){
            ViewHolder holder;
            View row = convertView;

            if(row == null){
                LayoutInflater inflater = getLayoutInflater();
                row = inflater.inflate(R.layout.list_outstanding, parent, false);
                //convertView = mInflater.inflate(R.layout.list_outstanding, parent, false);

                holder = new ViewHolder();
                holder.rlList = (RelativeLayout) convertView.findViewById(R.id.rllist);
                holder.tvContDate = (TextView) row.findViewById(R.id.outstanding_contractdate);
                holder.tvContNo = (TextView) row.findViewById(R.id.outstanding_contractno); 
                holder.tvContAmount = (TextView) row.findViewById(R.id.outstanding_contractamount);

                row.setTag(holder);
            } else {
                holder = (ViewHolder) row.getTag(); 
            }

                holder.tvContDate.setText(llData.get(position).split(",")[0].trim());
                holder.tvContNo.setText(llData.get(position).split(",")[1].trim());
                holder.tvContAmount.setText(llData.get(position).split(",")[2].trim());

                if(position%2 != 0)
                    holder.rlList.setBackgroundColor(0x00FF00);
                else
                    holder.rlList.setBackgroundColor(0XFF0000); 

            return(row);
        }
</code></pre>

<p>after running application when i reach to this code, an error occurs. according to LogCat it is "Null Pointer Exception" and points to this line in getView():</p>

<pre><code>holder.rlList = (RelativeLayout) convertView.findViewById(R.id.rllist);
</code></pre>

<p>it seems everything is OK, but I don't know where my problem is?!!!</p>

<p>===========</p>

<h1>Update</h1>

<p>I have changed above line to:</p>

<pre><code>holder.rlList = (RelativeLayout) row.findViewById(R.id.rllist);
</code></pre>

<p>and now i have my result but background did not applied?!!!</p>
