I have a GridView with each cell containing some text, and I want to be able to set the background colour of individual cells.
The XML for my GridView is:
<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">
</GridView>
The code for my GridView is:
GridView gridView = (GridView) findViewById(R.id.students_grid);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, student_array);
gridView.setAdapter(adapter);
I had hoped I would be able to set the background colour of individual cells using:
gridView.getChildAt(random_student).setBackgroundColor(Color.parseColor("#18A608"));
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.
Any ideas where I go next?