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:
You need to create a custom layout and use it in your adapter instead of android.R.layout.simple_list_item_1
. For example:
(I simply copied the latest version of simple_list_item_1.xml
and added the new background color at the end.)
Save this as grid_layout.xml
in res/layout
and change your adapter's constructor to:
ArrayAdapter adapter = new ArrayAdapter(this, R.layout.grid_layout, student_array);