Gautham Raj Ayyapparaj Gautham Raj Ayyapparaj - 1 year ago 65
Android Question

How to change Gridview's cell colour dynamically?

I am developing a simple android application for learning gridview. My requirement is to create a 2x2 grid which changes colours dynamically like a serial light circuit one by one, and others should be in white colour.

Please suggest a way to do this.

Answer Source

Create custom ArrayAdapter

new ArrayAdapter<String>(context, android.R.layout.simple_list_item_1, student_array) {
  public View getView(int position, View convertView, ViewGroup parent) {
    View view = super.getView(position, convertView, parent);

    int color = 0x00FFFFFF; // Transparent
    if (condition) {
      color = 0x00000000; // Black


    return view;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download