Gautham Raj Ayyapparaj
Gautham Raj Ayyapparaj

Reputation: 333

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.

Upvotes: 0

Views: 484

Answers (1)

Deepak Sachdeva
Deepak Sachdeva

Reputation: 1010

Create custom ArrayAdapter

new ArrayAdapter<String>(context, android.R.layout.simple_list_item_1, student_array) {
  @Override
  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
    }

    view.setBackgroundColor(color);

    return view;
  }
};

Upvotes: 1

Related Questions