Change background color of ListView item from Fragment
<p>I have a <code>Fragment</code> that is implementing a <code>ListView</code>. I have a global reference of this <code>ListView</code> in the <code>Fragment</code>class and i want to change the background color of the <code>ListView</code> item in <code>updateStep(int position)</code> method. I don't want to change the color of every item in the list. I am doing some processing in the Fragment and i want to change the color of the <code>ListView</code> item accordingly. </p>

<p>My <code>updateStep</code> method is simple:</p>

<pre><code>public void updateStep(int position) {
        if(stepsListView != null)
             stepsListView.getChildAt(position).setBackgroundColor(Color.GREEN);    
}
</code></pre>

<p>But the <code>getChildAt(position)</code> is returning null.What is the other way to get the item and update the color of an item. </p>

<p>The list_item.xml looks like this:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:padding="8dp"&gt;
    &lt;TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:textSize="@dimen/standard_text_size"
        android:textColor="@color/gray"
        android:text="@string/about_text_default"
        android:id="@+id/text_list_item"&gt;
    &lt;/TextView&gt;
    &lt;TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:textSize="16sp"
        android:textColor="@color/gray"
        android:text="@string/about_text_default"
        android:id="@+id/test_list_item_description"&gt;
    &lt;/TextView&gt;
&lt;/LinearLayout&gt;
</code></pre>

<p>and the fragment (that has a list) looks like this:</p>

<pre><code>&lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.carmanah.views.fragments.TestListFragment"&gt;

    &lt;LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"&gt;

        &lt;TextView
            android:id="@+id/text_heading"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:textColor="@color/gray"
            android:textStyle="bold"
            android:textSize="@dimen/standard_heading_text_size"
            android:text="@string/heading_text_tests"&gt;

        &lt;/TextView&gt;

        &lt;ListView
            android:id="@+id/task_list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:minHeight="@dimen/standard_text_size"
            android:divider="@color/gray"
            android:dividerHeight="2dip"&gt;

        &lt;/ListView&gt;
    &lt;/LinearLayout&gt;
&lt;/FrameLayout&gt;
</code></pre>

<p>P.S. I am using <code>CustomArrayAdapter</code> for this list.</p>