title: How to set the background colour of individual gridview cells
body: <p>I have a GridView with each cell containing some text, and I want to be able to set the background colour of individual cells.</p>
  
  <p>The XML for my GridView is:</p>
  
  <pre><code>&lt;GridView android:id="@+id/students_grid"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:numColumns="6"
            android:gravity="center"
            android:stretchMode="columnWidth"&gt;
  &lt;/GridView&gt;
  </code></pre>
  
  <p>The code for my GridView is:</p>
  
  <pre><code>GridView gridView = (GridView) findViewById(R.id.students_grid);
  ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1, student_array);
  gridView.setAdapter(adapter);
  </code></pre>
  
  <p>I had hoped I would be able to set the background colour of individual cells using:</p>
  
  <pre><code>gridView.getChildAt(random_student).setBackgroundColor(Color.parseColor("#18A608"));
  </code></pre>
  
  <p>However, this throws a null pointer exception, and on further examination it seems that gridview.getChildCount() returns 0. I have seen that gridview.getCount returns the number of items in the gridview correctly, but this doesn't help me to set the background colour of individual cells.</p>
  
  <p>Any ideas where I go next?</p>